#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1 << (x))
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = 1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int inf = 1e9; // INT_MAX;
const long long llinf = 1e18; // LLONG_MAX;
template<class X, class Y>
bool minimize(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y>
bool maximize(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
template<class X, class Y>
bool add(X &a, Y b) {
a += b;
while (a >= mod) a -= mod;
while (a < 0) a += mod;
return true;
}
int n;
pair<long long, long long> a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i].fi;
for (int i = 1; i <= n; ++i)
cin >> a[i].se;
sort(a + 1, a + n + 1, [&] (pair<long long, long long> x, pair<long long, long long> y) {
return x.fi + x.se < y.fi + y.se;
});
priority_queue<long long> q;
int level = 0, res = 0;
for (int i = 1; i <= n; ++i) {
level += a[i].fi;
q.push(a[i].fi);
while (level > a[i].fi + a[i].se) {
level -= q.top();
q.pop();
}
res = max(res, (int) q.size());
}
cout << res;
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
18040 KB |
Output is correct |
2 |
Correct |
124 ms |
18312 KB |
Output is correct |
3 |
Correct |
133 ms |
18428 KB |
Output is correct |
4 |
Correct |
124 ms |
18004 KB |
Output is correct |
5 |
Correct |
123 ms |
18072 KB |
Output is correct |
6 |
Correct |
123 ms |
17404 KB |
Output is correct |
7 |
Correct |
130 ms |
16468 KB |
Output is correct |
8 |
Correct |
121 ms |
17140 KB |
Output is correct |
9 |
Correct |
123 ms |
17340 KB |
Output is correct |
10 |
Correct |
121 ms |
17408 KB |
Output is correct |
11 |
Correct |
111 ms |
18128 KB |
Output is correct |
12 |
Correct |
109 ms |
22252 KB |
Output is correct |
13 |
Correct |
114 ms |
18148 KB |
Output is correct |
14 |
Correct |
108 ms |
22220 KB |
Output is correct |
15 |
Correct |
106 ms |
20332 KB |
Output is correct |
16 |
Correct |
130 ms |
17620 KB |
Output is correct |
17 |
Correct |
124 ms |
17596 KB |
Output is correct |
18 |
Correct |
123 ms |
17780 KB |
Output is correct |
19 |
Correct |
123 ms |
17140 KB |
Output is correct |
20 |
Correct |
120 ms |
17132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
476 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
636 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
3 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 |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
125 ms |
18040 KB |
Output is correct |
22 |
Correct |
124 ms |
18312 KB |
Output is correct |
23 |
Correct |
133 ms |
18428 KB |
Output is correct |
24 |
Correct |
124 ms |
18004 KB |
Output is correct |
25 |
Correct |
123 ms |
18072 KB |
Output is correct |
26 |
Correct |
123 ms |
17404 KB |
Output is correct |
27 |
Correct |
130 ms |
16468 KB |
Output is correct |
28 |
Correct |
121 ms |
17140 KB |
Output is correct |
29 |
Correct |
123 ms |
17340 KB |
Output is correct |
30 |
Correct |
121 ms |
17408 KB |
Output is correct |
31 |
Correct |
111 ms |
18128 KB |
Output is correct |
32 |
Correct |
109 ms |
22252 KB |
Output is correct |
33 |
Correct |
114 ms |
18148 KB |
Output is correct |
34 |
Correct |
108 ms |
22220 KB |
Output is correct |
35 |
Correct |
106 ms |
20332 KB |
Output is correct |
36 |
Correct |
130 ms |
17620 KB |
Output is correct |
37 |
Correct |
124 ms |
17596 KB |
Output is correct |
38 |
Correct |
123 ms |
17780 KB |
Output is correct |
39 |
Correct |
123 ms |
17140 KB |
Output is correct |
40 |
Correct |
120 ms |
17132 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
476 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
636 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
61 |
Correct |
2 ms |
604 KB |
Output is correct |
62 |
Correct |
3 ms |
604 KB |
Output is correct |
63 |
Correct |
2 ms |
604 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 |
604 KB |
Output is correct |
67 |
Correct |
2 ms |
604 KB |
Output is correct |
68 |
Correct |
2 ms |
604 KB |
Output is correct |
69 |
Correct |
1 ms |
604 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 |
348 KB |
Output is correct |
73 |
Correct |
139 ms |
18220 KB |
Output is correct |
74 |
Correct |
130 ms |
17920 KB |
Output is correct |
75 |
Correct |
137 ms |
18116 KB |
Output is correct |
76 |
Correct |
154 ms |
18476 KB |
Output is correct |
77 |
Correct |
129 ms |
18436 KB |
Output is correct |
78 |
Correct |
147 ms |
18900 KB |
Output is correct |
79 |
Correct |
137 ms |
18900 KB |
Output is correct |
80 |
Correct |
136 ms |
19024 KB |
Output is correct |
81 |
Correct |
137 ms |
19064 KB |
Output is correct |
82 |
Correct |
141 ms |
19092 KB |
Output is correct |
83 |
Correct |
163 ms |
19540 KB |
Output is correct |
84 |
Correct |
140 ms |
19580 KB |
Output is correct |
85 |
Correct |
143 ms |
19548 KB |
Output is correct |
86 |
Correct |
140 ms |
19448 KB |
Output is correct |
87 |
Correct |
138 ms |
19432 KB |
Output is correct |
88 |
Correct |
130 ms |
22988 KB |
Output is correct |
89 |
Correct |
131 ms |
21748 KB |
Output is correct |
90 |
Correct |
134 ms |
21488 KB |
Output is correct |
91 |
Correct |
127 ms |
22476 KB |
Output is correct |
92 |
Correct |
128 ms |
20988 KB |
Output is correct |
93 |
Correct |
126 ms |
21616 KB |
Output is correct |
94 |
Correct |
120 ms |
21108 KB |
Output is correct |
95 |
Correct |
133 ms |
21648 KB |
Output is correct |
96 |
Correct |
120 ms |
21964 KB |
Output is correct |
97 |
Correct |
130 ms |
21356 KB |
Output is correct |
98 |
Correct |
128 ms |
18552 KB |
Output is correct |
99 |
Correct |
138 ms |
18428 KB |
Output is correct |
100 |
Correct |
134 ms |
18548 KB |
Output is correct |
101 |
Correct |
110 ms |
20972 KB |
Output is correct |
102 |
Correct |
111 ms |
20884 KB |
Output is correct |