#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 10;
int x[N], l[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> x[i];
vector <int> order;
for (int i = 1; i <= n; i++) {
cin >> l[i];
order.pb(i);
}
sort(all(order), [&] (int a, int b) { return x[a] + l[a] < x[b] + l[b];});
priority_queue <ll> pq;
ll sum = 0;
for (auto i : order) {
if (sum <= l[i]) {
sum += x[i];
pq.push(x[i]);
} else {
if (pq.empty())
continue;
ll t = pq.top();
if (t > x[i] && sum - t + x[i] <= l[i]) {
pq.pop();
pq.push(x[i]);
sum += (x[i] - t);
}
}
}
cout << sz(pq) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
17968 KB |
Output is correct |
2 |
Correct |
119 ms |
18080 KB |
Output is correct |
3 |
Correct |
120 ms |
17864 KB |
Output is correct |
4 |
Correct |
124 ms |
17864 KB |
Output is correct |
5 |
Correct |
125 ms |
17860 KB |
Output is correct |
6 |
Correct |
118 ms |
17352 KB |
Output is correct |
7 |
Correct |
112 ms |
16584 KB |
Output is correct |
8 |
Correct |
116 ms |
17196 KB |
Output is correct |
9 |
Correct |
115 ms |
17256 KB |
Output is correct |
10 |
Correct |
114 ms |
17348 KB |
Output is correct |
11 |
Correct |
106 ms |
18828 KB |
Output is correct |
12 |
Correct |
109 ms |
21556 KB |
Output is correct |
13 |
Correct |
106 ms |
19000 KB |
Output is correct |
14 |
Correct |
107 ms |
21368 KB |
Output is correct |
15 |
Correct |
104 ms |
20548 KB |
Output is correct |
16 |
Correct |
110 ms |
17864 KB |
Output is correct |
17 |
Correct |
113 ms |
17988 KB |
Output is correct |
18 |
Correct |
111 ms |
18212 KB |
Output is correct |
19 |
Correct |
110 ms |
17608 KB |
Output is correct |
20 |
Correct |
109 ms |
17092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
0 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
119 ms |
17968 KB |
Output is correct |
22 |
Correct |
119 ms |
18080 KB |
Output is correct |
23 |
Correct |
120 ms |
17864 KB |
Output is correct |
24 |
Correct |
124 ms |
17864 KB |
Output is correct |
25 |
Correct |
125 ms |
17860 KB |
Output is correct |
26 |
Correct |
118 ms |
17352 KB |
Output is correct |
27 |
Correct |
112 ms |
16584 KB |
Output is correct |
28 |
Correct |
116 ms |
17196 KB |
Output is correct |
29 |
Correct |
115 ms |
17256 KB |
Output is correct |
30 |
Correct |
114 ms |
17348 KB |
Output is correct |
31 |
Correct |
106 ms |
18828 KB |
Output is correct |
32 |
Correct |
109 ms |
21556 KB |
Output is correct |
33 |
Correct |
106 ms |
19000 KB |
Output is correct |
34 |
Correct |
107 ms |
21368 KB |
Output is correct |
35 |
Correct |
104 ms |
20548 KB |
Output is correct |
36 |
Correct |
110 ms |
17864 KB |
Output is correct |
37 |
Correct |
113 ms |
17988 KB |
Output is correct |
38 |
Correct |
111 ms |
18212 KB |
Output is correct |
39 |
Correct |
110 ms |
17608 KB |
Output is correct |
40 |
Correct |
109 ms |
17092 KB |
Output is correct |
41 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |