#include <bits/stdc++.h>
using namespace std;
#define int ll
#define endl '\n' //comment for interactive
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define re resize
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin()+1, (x).end()
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define print(x) cout << #x << ": " << x << endl << flush
typedef long long ll;
typedef vector<int> vi;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<ii> vii;
typedef vector<ti> vti;
typedef vector<vi> vvi;
typedef priority_queue<int> pq;
template<class T> bool ckmin(T&a, T b) { bool B = a > b; a = min(a, b); return B; }
template<class T> bool ckmax(T&a, T b) { bool B = a < b; a = max(a, b); return B; }
const int inf = 1e17;
void solve() {
int n; cin >> n;
vti g(n+1);
loop1(i, n) cin >> g[i][1]; // x
loop1(i, n) cin >> g[i][2]; // l
loop1(i, n) g[i][0] = g[i][1] + g[i][2];
sort(all1(g));
priority_queue<int> pq;
int exp = 0;
loop1(i, n) {
if(exp <= g[i][2]) {
pq.push(g[i][1]);
exp += g[i][1];
} else if(exp - pq.top() <= g[i][2] and pq.top() > g[i][1]) {
exp -= pq.top();
pq.pop();
pq.push(g[i][1]);
exp += g[i][1];
}
}
cout << pq.size() << endl;
}
signed main() {
fast_io;
int t = 1; //cin >> t;
while(t--)
solve();
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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
12368 KB |
Output is correct |
2 |
Correct |
115 ms |
21328 KB |
Output is correct |
3 |
Correct |
118 ms |
21328 KB |
Output is correct |
4 |
Correct |
118 ms |
21392 KB |
Output is correct |
5 |
Correct |
147 ms |
21332 KB |
Output is correct |
6 |
Correct |
112 ms |
20816 KB |
Output is correct |
7 |
Correct |
118 ms |
19848 KB |
Output is correct |
8 |
Correct |
114 ms |
20564 KB |
Output is correct |
9 |
Correct |
110 ms |
20696 KB |
Output is correct |
10 |
Correct |
112 ms |
20816 KB |
Output is correct |
11 |
Correct |
115 ms |
21492 KB |
Output is correct |
12 |
Correct |
112 ms |
25072 KB |
Output is correct |
13 |
Correct |
115 ms |
21624 KB |
Output is correct |
14 |
Correct |
108 ms |
23956 KB |
Output is correct |
15 |
Correct |
108 ms |
24204 KB |
Output is correct |
16 |
Correct |
131 ms |
20944 KB |
Output is correct |
17 |
Correct |
143 ms |
20872 KB |
Output is correct |
18 |
Correct |
127 ms |
20944 KB |
Output is correct |
19 |
Correct |
114 ms |
20484 KB |
Output is correct |
20 |
Correct |
115 ms |
20348 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
2 ms |
568 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
600 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
2 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
112 ms |
12368 KB |
Output is correct |
22 |
Correct |
115 ms |
21328 KB |
Output is correct |
23 |
Correct |
118 ms |
21328 KB |
Output is correct |
24 |
Correct |
118 ms |
21392 KB |
Output is correct |
25 |
Correct |
147 ms |
21332 KB |
Output is correct |
26 |
Correct |
112 ms |
20816 KB |
Output is correct |
27 |
Correct |
118 ms |
19848 KB |
Output is correct |
28 |
Correct |
114 ms |
20564 KB |
Output is correct |
29 |
Correct |
110 ms |
20696 KB |
Output is correct |
30 |
Correct |
112 ms |
20816 KB |
Output is correct |
31 |
Correct |
115 ms |
21492 KB |
Output is correct |
32 |
Correct |
112 ms |
25072 KB |
Output is correct |
33 |
Correct |
115 ms |
21624 KB |
Output is correct |
34 |
Correct |
108 ms |
23956 KB |
Output is correct |
35 |
Correct |
108 ms |
24204 KB |
Output is correct |
36 |
Correct |
131 ms |
20944 KB |
Output is correct |
37 |
Correct |
143 ms |
20872 KB |
Output is correct |
38 |
Correct |
127 ms |
20944 KB |
Output is correct |
39 |
Correct |
114 ms |
20484 KB |
Output is correct |
40 |
Correct |
115 ms |
20348 KB |
Output is correct |
41 |
Correct |
2 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
600 KB |
Output is correct |
48 |
Correct |
2 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
604 KB |
Output is correct |
53 |
Correct |
1 ms |
600 KB |
Output is correct |
54 |
Correct |
2 ms |
568 KB |
Output is correct |
55 |
Correct |
2 ms |
600 KB |
Output is correct |
56 |
Correct |
2 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
1 ms |
600 KB |
Output is correct |
67 |
Correct |
2 ms |
604 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
2 ms |
604 KB |
Output is correct |
70 |
Correct |
2 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
134 ms |
21660 KB |
Output is correct |
74 |
Correct |
128 ms |
21516 KB |
Output is correct |
75 |
Correct |
124 ms |
21532 KB |
Output is correct |
76 |
Correct |
127 ms |
21584 KB |
Output is correct |
77 |
Correct |
115 ms |
21644 KB |
Output is correct |
78 |
Correct |
117 ms |
22276 KB |
Output is correct |
79 |
Correct |
118 ms |
22228 KB |
Output is correct |
80 |
Correct |
121 ms |
22228 KB |
Output is correct |
81 |
Correct |
155 ms |
22408 KB |
Output is correct |
82 |
Correct |
117 ms |
22224 KB |
Output is correct |
83 |
Correct |
120 ms |
22736 KB |
Output is correct |
84 |
Correct |
117 ms |
22736 KB |
Output is correct |
85 |
Correct |
120 ms |
22792 KB |
Output is correct |
86 |
Correct |
122 ms |
22660 KB |
Output is correct |
87 |
Correct |
122 ms |
22804 KB |
Output is correct |
88 |
Correct |
119 ms |
24776 KB |
Output is correct |
89 |
Correct |
124 ms |
25288 KB |
Output is correct |
90 |
Correct |
119 ms |
26008 KB |
Output is correct |
91 |
Correct |
118 ms |
24272 KB |
Output is correct |
92 |
Correct |
117 ms |
25600 KB |
Output is correct |
93 |
Correct |
121 ms |
24596 KB |
Output is correct |
94 |
Correct |
121 ms |
24328 KB |
Output is correct |
95 |
Correct |
116 ms |
23836 KB |
Output is correct |
96 |
Correct |
114 ms |
24264 KB |
Output is correct |
97 |
Correct |
115 ms |
25616 KB |
Output is correct |
98 |
Correct |
116 ms |
21788 KB |
Output is correct |
99 |
Correct |
119 ms |
21788 KB |
Output is correct |
100 |
Correct |
119 ms |
21844 KB |
Output is correct |
101 |
Correct |
117 ms |
25508 KB |
Output is correct |
102 |
Correct |
115 ms |
25288 KB |
Output is correct |