-
Notifications
You must be signed in to change notification settings - Fork 1
/
P3545.cc
61 lines (55 loc) · 1.04 KB
/
P3545.cc
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
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
using std::priority_queue;
using std::vector;
#define N 250000
int a[N];
bool collect[N];
struct PNode {
int b, i;
PNode(int b, int i) : b(b), i(i) {
}
};
struct cmp {
bool operator() (PNode& x, PNode& y) {
return x.b < y.b;
}
};
priority_queue<PNode, vector<PNode>, cmp> q;
int main() {
int n, b;
long long sum = 0ll;
int ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
for (int i = 0; i < n; i++) {
scanf("%d", &b);
sum += a[i];
if (sum > b) {
sum -= b;
ans++;
collect[i] = true;
q.push(PNode(b, i));
}
else if( (!q.empty()) && q.top().b > b) {
sum += q.top().b;
collect[q.top().i] = false;
q.pop();
sum -= b;
collect[i] = true;
q.push(PNode(b, i));
}
}
printf("%d\n", ans);
bool first = true;
for (int i = 0; i < n; i++)
if (collect[i]) {
if (first) first = false;
else putchar(' ');
printf("%d", i + 1);
}
exit(0);
}