#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B>
string to_string(pair<A, B>);
string to_string(string S) {
return '"' + S + '"';
}
string to_string(const char* c) {
return to_string(string(c));
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template<size_t T>
string to_string(bitset<T> bs) {
return bs.to_string();
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < int(v.size()); ++i) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(v[i]);
}
return res + "}";
}
template<typename T>
string to_string(T v) {
string res = "{";
for (auto e : v) {
if (int(res.size()) > 1) {
res += ", ";
}
res += to_string(e);
}
return res + "}";
}
template<typename T>
string to_string(priority_queue<T> pq) {
vector<T> a;
while (!pq.empty()) {
a.push_back(pq.top());
pq.pop();
}
return to_string(a);
}
template<typename A, typename B>
string to_string(pair<A, B> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename H, typename... T>
void debug_out(H head, T... tail) {
cerr << " " << to_string(head);
debug_out(tail...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(37)
#endif
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> X(N), L(N);
for (int i = 0; i < N; ++i) {
cin >> X[i];
}
for (int i = 0; i < N; ++i) {
cin >> L[i];
}
vector<int> S(N);
for (int i = 0; i < N; ++i) {
S[i] = X[i] + L[i];
}
vector<int> ord(N);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int x, int y) {
return S[x] < S[y];
});
priority_queue<int> pq;
long long last = 0;
for (auto i : ord) {
pq.push(X[i]);
last += X[i];
if (last > S[i]) {
last -= pq.top();
pq.pop();
}
}
cout << int(pq.size()) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
452 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
13356 KB |
Output is correct |
2 |
Correct |
135 ms |
13296 KB |
Output is correct |
3 |
Correct |
136 ms |
13396 KB |
Output is correct |
4 |
Correct |
141 ms |
13392 KB |
Output is correct |
5 |
Correct |
143 ms |
13432 KB |
Output is correct |
6 |
Correct |
133 ms |
13072 KB |
Output is correct |
7 |
Correct |
140 ms |
12808 KB |
Output is correct |
8 |
Correct |
145 ms |
12880 KB |
Output is correct |
9 |
Correct |
134 ms |
12884 KB |
Output is correct |
10 |
Correct |
135 ms |
12884 KB |
Output is correct |
11 |
Correct |
119 ms |
13524 KB |
Output is correct |
12 |
Correct |
118 ms |
14444 KB |
Output is correct |
13 |
Correct |
115 ms |
13512 KB |
Output is correct |
14 |
Correct |
119 ms |
14456 KB |
Output is correct |
15 |
Correct |
115 ms |
14548 KB |
Output is correct |
16 |
Correct |
131 ms |
13268 KB |
Output is correct |
17 |
Correct |
139 ms |
13264 KB |
Output is correct |
18 |
Correct |
132 ms |
13272 KB |
Output is correct |
19 |
Correct |
138 ms |
12884 KB |
Output is correct |
20 |
Correct |
133 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
452 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
624 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
588 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
2 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
2 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
600 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
580 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
600 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
452 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
145 ms |
13356 KB |
Output is correct |
22 |
Correct |
135 ms |
13296 KB |
Output is correct |
23 |
Correct |
136 ms |
13396 KB |
Output is correct |
24 |
Correct |
141 ms |
13392 KB |
Output is correct |
25 |
Correct |
143 ms |
13432 KB |
Output is correct |
26 |
Correct |
133 ms |
13072 KB |
Output is correct |
27 |
Correct |
140 ms |
12808 KB |
Output is correct |
28 |
Correct |
145 ms |
12880 KB |
Output is correct |
29 |
Correct |
134 ms |
12884 KB |
Output is correct |
30 |
Correct |
135 ms |
12884 KB |
Output is correct |
31 |
Correct |
119 ms |
13524 KB |
Output is correct |
32 |
Correct |
118 ms |
14444 KB |
Output is correct |
33 |
Correct |
115 ms |
13512 KB |
Output is correct |
34 |
Correct |
119 ms |
14456 KB |
Output is correct |
35 |
Correct |
115 ms |
14548 KB |
Output is correct |
36 |
Correct |
131 ms |
13268 KB |
Output is correct |
37 |
Correct |
139 ms |
13264 KB |
Output is correct |
38 |
Correct |
132 ms |
13272 KB |
Output is correct |
39 |
Correct |
138 ms |
12884 KB |
Output is correct |
40 |
Correct |
133 ms |
12884 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
624 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
600 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
588 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
2 ms |
600 KB |
Output is correct |
52 |
Correct |
2 ms |
464 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
600 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
2 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
600 KB |
Output is correct |
60 |
Correct |
2 ms |
604 KB |
Output is correct |
61 |
Correct |
2 ms |
604 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
2 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
600 KB |
Output is correct |
65 |
Correct |
2 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
580 KB |
Output is correct |
67 |
Correct |
1 ms |
604 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
2 ms |
600 KB |
Output is correct |
70 |
Correct |
2 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
456 KB |
Output is correct |
73 |
Correct |
135 ms |
17532 KB |
Output is correct |
74 |
Correct |
137 ms |
17680 KB |
Output is correct |
75 |
Correct |
132 ms |
17656 KB |
Output is correct |
76 |
Correct |
137 ms |
17664 KB |
Output is correct |
77 |
Correct |
133 ms |
17548 KB |
Output is correct |
78 |
Correct |
138 ms |
17792 KB |
Output is correct |
79 |
Correct |
146 ms |
18156 KB |
Output is correct |
80 |
Correct |
141 ms |
17876 KB |
Output is correct |
81 |
Correct |
141 ms |
17876 KB |
Output is correct |
82 |
Correct |
152 ms |
18184 KB |
Output is correct |
83 |
Correct |
140 ms |
17796 KB |
Output is correct |
84 |
Correct |
144 ms |
17872 KB |
Output is correct |
85 |
Correct |
148 ms |
18064 KB |
Output is correct |
86 |
Correct |
143 ms |
17872 KB |
Output is correct |
87 |
Correct |
140 ms |
17920 KB |
Output is correct |
88 |
Correct |
140 ms |
18384 KB |
Output is correct |
89 |
Correct |
138 ms |
18300 KB |
Output is correct |
90 |
Correct |
137 ms |
18172 KB |
Output is correct |
91 |
Correct |
133 ms |
18316 KB |
Output is correct |
92 |
Correct |
142 ms |
18400 KB |
Output is correct |
93 |
Correct |
127 ms |
17872 KB |
Output is correct |
94 |
Correct |
126 ms |
17924 KB |
Output is correct |
95 |
Correct |
136 ms |
17796 KB |
Output is correct |
96 |
Correct |
133 ms |
18032 KB |
Output is correct |
97 |
Correct |
128 ms |
18040 KB |
Output is correct |
98 |
Correct |
142 ms |
17680 KB |
Output is correct |
99 |
Correct |
137 ms |
17624 KB |
Output is correct |
100 |
Correct |
149 ms |
18004 KB |
Output is correct |
101 |
Correct |
117 ms |
17364 KB |
Output is correct |
102 |
Correct |
117 ms |
17524 KB |
Output is correct |