#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 69, pr = 31;
const int mxn = 5e5 + 5, mxq = 1e5 + 5, sq = 300, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int n;
pll p[mxn + 1];
bool cmp(pll a, pll b){
return(a.fi + a.se < b.fi + b.se);
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> p[i].fi;
for(int i = 1; i <= n; i++)cin >> p[i].se;
sort(p + 1, p + n + 1, cmp);
priority_queue<ll, vt<ll>>pq;
ll tot = 0;
for(int i = 1; i <= n; i++){
if(tot > p[i].se){
if(pq.top() > p[i].fi){
tot -= pq.top(); tot += p[i].fi;
pq.pop(); pq.push(p[i].fi);
}
}else{
pq.push(p[i].fi); tot += p[i].fi;
}
}
cout << sz(pq);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("netw.inp", "r", stdin);
//freopen("netw.out", "w", stdout);
int ttt; ttt = 1;
while(ttt--){
solve();
}
return(0);
}
/*
1
5 7 2
1 1 1
3 1 2
2 2 3
4 2 4
2 4 2
1 5 5
3 5 2
5 3
2 7
3 3 1
1 1 1
1 2 2
1 3 3
3 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
356 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 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 |
139 ms |
17472 KB |
Output is correct |
2 |
Correct |
125 ms |
17528 KB |
Output is correct |
3 |
Correct |
132 ms |
17740 KB |
Output is correct |
4 |
Correct |
123 ms |
17488 KB |
Output is correct |
5 |
Correct |
123 ms |
17492 KB |
Output is correct |
6 |
Correct |
118 ms |
16720 KB |
Output is correct |
7 |
Correct |
119 ms |
16208 KB |
Output is correct |
8 |
Correct |
119 ms |
16724 KB |
Output is correct |
9 |
Correct |
121 ms |
16700 KB |
Output is correct |
10 |
Correct |
121 ms |
17176 KB |
Output is correct |
11 |
Correct |
107 ms |
17612 KB |
Output is correct |
12 |
Correct |
111 ms |
19916 KB |
Output is correct |
13 |
Correct |
116 ms |
17612 KB |
Output is correct |
14 |
Correct |
109 ms |
20420 KB |
Output is correct |
15 |
Correct |
107 ms |
20172 KB |
Output is correct |
16 |
Correct |
117 ms |
17184 KB |
Output is correct |
17 |
Correct |
119 ms |
17360 KB |
Output is correct |
18 |
Correct |
119 ms |
17216 KB |
Output is correct |
19 |
Correct |
118 ms |
16596 KB |
Output is correct |
20 |
Correct |
116 ms |
16596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
356 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 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 |
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 |
636 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 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 |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 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 |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
600 KB |
Output is correct |
40 |
Correct |
2 ms |
604 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 |
1 ms |
856 KB |
Output is correct |
45 |
Correct |
2 ms |
628 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 |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
0 ms |
356 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 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 |
139 ms |
17472 KB |
Output is correct |
22 |
Correct |
125 ms |
17528 KB |
Output is correct |
23 |
Correct |
132 ms |
17740 KB |
Output is correct |
24 |
Correct |
123 ms |
17488 KB |
Output is correct |
25 |
Correct |
123 ms |
17492 KB |
Output is correct |
26 |
Correct |
118 ms |
16720 KB |
Output is correct |
27 |
Correct |
119 ms |
16208 KB |
Output is correct |
28 |
Correct |
119 ms |
16724 KB |
Output is correct |
29 |
Correct |
121 ms |
16700 KB |
Output is correct |
30 |
Correct |
121 ms |
17176 KB |
Output is correct |
31 |
Correct |
107 ms |
17612 KB |
Output is correct |
32 |
Correct |
111 ms |
19916 KB |
Output is correct |
33 |
Correct |
116 ms |
17612 KB |
Output is correct |
34 |
Correct |
109 ms |
20420 KB |
Output is correct |
35 |
Correct |
107 ms |
20172 KB |
Output is correct |
36 |
Correct |
117 ms |
17184 KB |
Output is correct |
37 |
Correct |
119 ms |
17360 KB |
Output is correct |
38 |
Correct |
119 ms |
17216 KB |
Output is correct |
39 |
Correct |
118 ms |
16596 KB |
Output is correct |
40 |
Correct |
116 ms |
16596 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 |
636 KB |
Output is correct |
46 |
Correct |
2 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 |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
2 ms |
604 KB |
Output is correct |
53 |
Correct |
2 ms |
604 KB |
Output is correct |
54 |
Correct |
2 ms |
604 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 |
2 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
600 KB |
Output is correct |
60 |
Correct |
2 ms |
604 KB |
Output is correct |
61 |
Correct |
2 ms |
604 KB |
Output is correct |
62 |
Correct |
2 ms |
604 KB |
Output is correct |
63 |
Correct |
2 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
856 KB |
Output is correct |
65 |
Correct |
2 ms |
628 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 |
1 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
600 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
133 ms |
17756 KB |
Output is correct |
74 |
Correct |
126 ms |
17528 KB |
Output is correct |
75 |
Correct |
136 ms |
17660 KB |
Output is correct |
76 |
Correct |
125 ms |
17744 KB |
Output is correct |
77 |
Correct |
127 ms |
17744 KB |
Output is correct |
78 |
Correct |
131 ms |
18372 KB |
Output is correct |
79 |
Correct |
141 ms |
18524 KB |
Output is correct |
80 |
Correct |
128 ms |
18384 KB |
Output is correct |
81 |
Correct |
137 ms |
18384 KB |
Output is correct |
82 |
Correct |
137 ms |
18668 KB |
Output is correct |
83 |
Correct |
136 ms |
18896 KB |
Output is correct |
84 |
Correct |
129 ms |
18800 KB |
Output is correct |
85 |
Correct |
140 ms |
19012 KB |
Output is correct |
86 |
Correct |
131 ms |
18880 KB |
Output is correct |
87 |
Correct |
139 ms |
18896 KB |
Output is correct |
88 |
Correct |
129 ms |
20836 KB |
Output is correct |
89 |
Correct |
133 ms |
21196 KB |
Output is correct |
90 |
Correct |
128 ms |
21964 KB |
Output is correct |
91 |
Correct |
135 ms |
22208 KB |
Output is correct |
92 |
Correct |
130 ms |
22184 KB |
Output is correct |
93 |
Correct |
128 ms |
21960 KB |
Output is correct |
94 |
Correct |
133 ms |
21960 KB |
Output is correct |
95 |
Correct |
127 ms |
20376 KB |
Output is correct |
96 |
Correct |
128 ms |
20820 KB |
Output is correct |
97 |
Correct |
124 ms |
20796 KB |
Output is correct |
98 |
Correct |
135 ms |
17860 KB |
Output is correct |
99 |
Correct |
126 ms |
17872 KB |
Output is correct |
100 |
Correct |
127 ms |
17880 KB |
Output is correct |
101 |
Correct |
123 ms |
19704 KB |
Output is correct |
102 |
Correct |
126 ms |
20428 KB |
Output is correct |