-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.cpp
70 lines (51 loc) · 1.44 KB
/
solution.cpp
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;
// Implementation Part
vector<int> jimOrders(vector<vector<int>> orders) {
vector<int> serve;
int time;
// traverse orders,
// calculate sum f order and time
// store that sum to serve
for(int i = 0; i < orders.size(); i++){
time = orders[i][0] + orders[i][1];
serve.push_back(time);
}
// make del equal to serve
// sort del, to find order of delivery
vector<int> del = serve;
sort(del.begin(), del.end());
// find index of del[i], i.e lowest delivery time
// in serve and use (index + 1)
for(int i = 0; i < serve.size(); i++){
int pos = find(serve.begin(), serve.end(), del[i]) - serve.begin();
serve[pos] = -1;
del[i] = pos + 1;
}
return del;
}
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;
}