-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jim and the Orders
69 lines (56 loc) · 1.43 KB
/
Jim and the Orders
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
// Complete the jimOrders function below.
vector<int> jimOrders(vector<vector<int>> orders) {
vector<vector<int>> ans(orders.size(),vector<int>(orders[0].size(),0));
vector<int> temp;
int small,i,j,sum=0,index,del;
for(i=0;i<orders.size();i++){
for(j=0;j<orders[i].size();j++){
sum+=orders[i][j];
}
ans[i][0] = sum;
ans[i][1] = i;
sum=0;
}
while(ans.size()){
small = ans[0][0];
index=ans[0][1];
del=0;
for(i=1;i<ans.size();i++){
if(small>ans[i][0]){
small=ans[i][0];
index=ans[i][1];
del=i;
}
}
temp.push_back(index+1);
ans.erase(ans.begin() + del);
}
return temp;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
vector<vector<int>> orders(n);
for (int i = 0; i < n; i++) {
orders[i].resize(2);
for (int j = 0; j < 2; j++) {
cin >> orders[i][j];
}
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
vector<int> result = jimOrders(orders);
for (int i = 0; i < result.size(); i++) {
fout << result[i];
if (i != result.size() - 1) {
fout << " ";
}
}
fout << "\n";
fout.close();
return 0;
}