#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> gyms(n);
for (int i = 0; i < n; i++) {
cin >> gyms[i].second;
}
for (int i = 0; i < n; i++) {
cin >> gyms[i].first;
}
sort(gyms.begin(), gyms.end());
long long level = 0;
int ans = 0;
priority_queue<long long> pq;
for (int i = 0; i < n; i++) {
if (level <= gyms[i].first) {
level += gyms[i].second;
pq.push(gyms[i].second);
ans++;
}
else {
long long x = pq.top();
if (level-x <= gyms[i].first && x >= gyms[i].second) {
pq.pop();
pq.push(gyms[i].second);
level -= x;
level += gyms[i].second;
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
269 ms |
13544 KB |
Output is correct |
2 |
Correct |
268 ms |
13800 KB |
Output is correct |
3 |
Correct |
271 ms |
13676 KB |
Output is correct |
4 |
Correct |
291 ms |
13536 KB |
Output is correct |
5 |
Correct |
263 ms |
13428 KB |
Output is correct |
6 |
Correct |
239 ms |
12884 KB |
Output is correct |
7 |
Correct |
227 ms |
12372 KB |
Output is correct |
8 |
Correct |
237 ms |
12628 KB |
Output is correct |
9 |
Correct |
244 ms |
12964 KB |
Output is correct |
10 |
Correct |
245 ms |
12884 KB |
Output is correct |
11 |
Correct |
214 ms |
13656 KB |
Output is correct |
12 |
Correct |
267 ms |
16092 KB |
Output is correct |
13 |
Correct |
228 ms |
13768 KB |
Output is correct |
14 |
Correct |
224 ms |
16324 KB |
Output is correct |
15 |
Correct |
215 ms |
17492 KB |
Output is correct |
16 |
Correct |
228 ms |
13152 KB |
Output is correct |
17 |
Correct |
230 ms |
13144 KB |
Output is correct |
18 |
Correct |
232 ms |
13116 KB |
Output is correct |
19 |
Correct |
222 ms |
12752 KB |
Output is correct |
20 |
Correct |
226 ms |
12516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |