/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 500005;
int n;
pair<int, int> a[N];
int ans = 0;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].first;
for (int i = 1; i <= n; i++)
cin >> a[i].second;
for (int i = 1; i <= n; i++)
a[i].second += a[i].first;
sort(a + 1, a + 1 + n, [](pair<int, int> x, pair<int, int> y) {
return x.second < y.second;
});
priority_queue<int> q;
for (int i = n; i >= 1; i--)
{
q.push(-a[i].first);
if(a[i-1].second == a[i].second)
continue;
int d = a[i].second - a[i - 1].second;
while (!q.empty() && d)
{
int x = -q.top();
q.pop();
if (x <= d)
{
d -= x;
ans++;
}
else
{
x -= d;
d = 0;
q.push(-x);
}
}
}
cout << ans << endl;
}
int main()
{
fastIO;
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
11188 KB |
Output is correct |
2 |
Correct |
169 ms |
11380 KB |
Output is correct |
3 |
Correct |
162 ms |
12244 KB |
Output is correct |
4 |
Correct |
162 ms |
11212 KB |
Output is correct |
5 |
Correct |
163 ms |
11220 KB |
Output is correct |
6 |
Correct |
152 ms |
10700 KB |
Output is correct |
7 |
Correct |
147 ms |
10448 KB |
Output is correct |
8 |
Correct |
149 ms |
10840 KB |
Output is correct |
9 |
Correct |
150 ms |
10836 KB |
Output is correct |
10 |
Correct |
158 ms |
10704 KB |
Output is correct |
11 |
Correct |
111 ms |
10360 KB |
Output is correct |
12 |
Correct |
113 ms |
10188 KB |
Output is correct |
13 |
Correct |
110 ms |
10364 KB |
Output is correct |
14 |
Correct |
112 ms |
10184 KB |
Output is correct |
15 |
Correct |
117 ms |
10360 KB |
Output is correct |
16 |
Correct |
125 ms |
10616 KB |
Output is correct |
17 |
Correct |
127 ms |
10476 KB |
Output is correct |
18 |
Correct |
129 ms |
10564 KB |
Output is correct |
19 |
Correct |
125 ms |
10448 KB |
Output is correct |
20 |
Correct |
124 ms |
10612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
480 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
2 ms |
484 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
2 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 |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
480 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
592 KB |
Output is correct |
47 |
Correct |
2 ms |
348 KB |
Output is correct |
48 |
Correct |
2 ms |
348 KB |
Output is correct |
49 |
Correct |
2 ms |
564 KB |
Output is correct |
50 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
165 ms |
11188 KB |
Output is correct |
22 |
Correct |
169 ms |
11380 KB |
Output is correct |
23 |
Correct |
162 ms |
12244 KB |
Output is correct |
24 |
Correct |
162 ms |
11212 KB |
Output is correct |
25 |
Correct |
163 ms |
11220 KB |
Output is correct |
26 |
Correct |
152 ms |
10700 KB |
Output is correct |
27 |
Correct |
147 ms |
10448 KB |
Output is correct |
28 |
Correct |
149 ms |
10840 KB |
Output is correct |
29 |
Correct |
150 ms |
10836 KB |
Output is correct |
30 |
Correct |
158 ms |
10704 KB |
Output is correct |
31 |
Correct |
111 ms |
10360 KB |
Output is correct |
32 |
Correct |
113 ms |
10188 KB |
Output is correct |
33 |
Correct |
110 ms |
10364 KB |
Output is correct |
34 |
Correct |
112 ms |
10184 KB |
Output is correct |
35 |
Correct |
117 ms |
10360 KB |
Output is correct |
36 |
Correct |
125 ms |
10616 KB |
Output is correct |
37 |
Correct |
127 ms |
10476 KB |
Output is correct |
38 |
Correct |
129 ms |
10564 KB |
Output is correct |
39 |
Correct |
125 ms |
10448 KB |
Output is correct |
40 |
Correct |
124 ms |
10612 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
2 ms |
604 KB |
Output is correct |
49 |
Correct |
2 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
480 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
2 ms |
604 KB |
Output is correct |
53 |
Correct |
2 ms |
484 KB |
Output is correct |
54 |
Correct |
2 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
2 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 |
604 KB |
Output is correct |
60 |
Correct |
2 ms |
480 KB |
Output is correct |
61 |
Correct |
2 ms |
348 KB |
Output is correct |
62 |
Correct |
2 ms |
348 KB |
Output is correct |
63 |
Correct |
2 ms |
348 KB |
Output is correct |
64 |
Correct |
2 ms |
604 KB |
Output is correct |
65 |
Correct |
2 ms |
604 KB |
Output is correct |
66 |
Correct |
2 ms |
592 KB |
Output is correct |
67 |
Correct |
2 ms |
348 KB |
Output is correct |
68 |
Correct |
2 ms |
348 KB |
Output is correct |
69 |
Correct |
2 ms |
564 KB |
Output is correct |
70 |
Correct |
2 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
468 KB |
Output is correct |
73 |
Correct |
162 ms |
11212 KB |
Output is correct |
74 |
Correct |
159 ms |
11212 KB |
Output is correct |
75 |
Correct |
160 ms |
11176 KB |
Output is correct |
76 |
Correct |
165 ms |
11396 KB |
Output is correct |
77 |
Correct |
158 ms |
11212 KB |
Output is correct |
78 |
Correct |
164 ms |
11216 KB |
Output is correct |
79 |
Correct |
167 ms |
11380 KB |
Output is correct |
80 |
Correct |
167 ms |
11360 KB |
Output is correct |
81 |
Correct |
164 ms |
11380 KB |
Output is correct |
82 |
Correct |
167 ms |
11468 KB |
Output is correct |
83 |
Correct |
173 ms |
11124 KB |
Output is correct |
84 |
Correct |
166 ms |
10952 KB |
Output is correct |
85 |
Correct |
168 ms |
11260 KB |
Output is correct |
86 |
Correct |
165 ms |
10956 KB |
Output is correct |
87 |
Correct |
167 ms |
10952 KB |
Output is correct |
88 |
Correct |
162 ms |
9424 KB |
Output is correct |
89 |
Correct |
182 ms |
9516 KB |
Output is correct |
90 |
Correct |
163 ms |
9456 KB |
Output is correct |
91 |
Correct |
168 ms |
9448 KB |
Output is correct |
92 |
Correct |
184 ms |
9396 KB |
Output is correct |
93 |
Correct |
155 ms |
8920 KB |
Output is correct |
94 |
Correct |
165 ms |
8916 KB |
Output is correct |
95 |
Correct |
158 ms |
8912 KB |
Output is correct |
96 |
Correct |
156 ms |
8920 KB |
Output is correct |
97 |
Correct |
160 ms |
8920 KB |
Output is correct |
98 |
Correct |
172 ms |
11468 KB |
Output is correct |
99 |
Correct |
162 ms |
11308 KB |
Output is correct |
100 |
Correct |
161 ms |
11328 KB |
Output is correct |
101 |
Correct |
105 ms |
8116 KB |
Output is correct |
102 |
Correct |
107 ms |
8040 KB |
Output is correct |