forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path165.cpp
More file actions
40 lines (37 loc) · 715 Bytes
/
165.cpp
File metadata and controls
40 lines (37 loc) · 715 Bytes
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
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
class player {
public:
int hei;
int pos;
player(int h, int p) : hei(h), pos(p) {}
bool operator < (const player &r) const {
return hei < r.hei;
}
};
int main() {
int n;
scanf("%d", &n);
vector<player> mm;
for (int i = 0; i < n; ++i) {
double a;
scanf("%lf", &a);
mm.push_back(player((int)(a * 1000000 - 2000000), i + 1));
}
sort(mm.begin(), mm.end());
int left = 0, right = n - 1, sum = 0;
printf("yes\n");
while (left <= right) {
if (sum <= 0) {
sum += mm[right].hei;
printf("%d ", mm[right--].pos);
} else {
sum += mm[left].hei;
printf("%d ", mm[left++].pos);
}
}
printf("\n");
return 0;
}