#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 make_pair(x[a] + l[a], -x[a]) < make_pair(x[b] + l[b], -x[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
8788 KB |
Output is correct |
2 |
Correct |
115 ms |
8776 KB |
Output is correct |
3 |
Correct |
118 ms |
8912 KB |
Output is correct |
4 |
Correct |
115 ms |
8776 KB |
Output is correct |
5 |
Correct |
120 ms |
8852 KB |
Output is correct |
6 |
Correct |
113 ms |
9028 KB |
Output is correct |
7 |
Correct |
112 ms |
8908 KB |
Output is correct |
8 |
Correct |
116 ms |
8908 KB |
Output is correct |
9 |
Correct |
113 ms |
9024 KB |
Output is correct |
10 |
Correct |
111 ms |
9160 KB |
Output is correct |
11 |
Correct |
104 ms |
11720 KB |
Output is correct |
12 |
Correct |
105 ms |
13896 KB |
Output is correct |
13 |
Correct |
103 ms |
11596 KB |
Output is correct |
14 |
Correct |
109 ms |
13900 KB |
Output is correct |
15 |
Correct |
107 ms |
13124 KB |
Output is correct |
16 |
Correct |
115 ms |
10184 KB |
Output is correct |
17 |
Correct |
113 ms |
10440 KB |
Output is correct |
18 |
Correct |
116 ms |
10412 KB |
Output is correct |
19 |
Correct |
111 ms |
9668 KB |
Output is correct |
20 |
Correct |
144 ms |
9388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 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 |
0 ms |
2396 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 |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
122 ms |
8788 KB |
Output is correct |
22 |
Correct |
115 ms |
8776 KB |
Output is correct |
23 |
Correct |
118 ms |
8912 KB |
Output is correct |
24 |
Correct |
115 ms |
8776 KB |
Output is correct |
25 |
Correct |
120 ms |
8852 KB |
Output is correct |
26 |
Correct |
113 ms |
9028 KB |
Output is correct |
27 |
Correct |
112 ms |
8908 KB |
Output is correct |
28 |
Correct |
116 ms |
8908 KB |
Output is correct |
29 |
Correct |
113 ms |
9024 KB |
Output is correct |
30 |
Correct |
111 ms |
9160 KB |
Output is correct |
31 |
Correct |
104 ms |
11720 KB |
Output is correct |
32 |
Correct |
105 ms |
13896 KB |
Output is correct |
33 |
Correct |
103 ms |
11596 KB |
Output is correct |
34 |
Correct |
109 ms |
13900 KB |
Output is correct |
35 |
Correct |
107 ms |
13124 KB |
Output is correct |
36 |
Correct |
115 ms |
10184 KB |
Output is correct |
37 |
Correct |
113 ms |
10440 KB |
Output is correct |
38 |
Correct |
116 ms |
10412 KB |
Output is correct |
39 |
Correct |
111 ms |
9668 KB |
Output is correct |
40 |
Correct |
144 ms |
9388 KB |
Output is correct |
41 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |