#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 5e5 +23, inf = LLONG_MAX, LL = 30;
void rush(){
int n;
cin>>n;
vector<pair<int,pair<int,int>>> lst(n);
int ans=0;
for(int i=0;i<n;i++){
cin>>lst[i].second.second;
}
for(int i=0;i<n;i++){
cin>>lst[i].second.first;
lst[i].first = lst[i].second.first + lst[i].second.second;
}
sort(all(lst));
int gain =0;
priority_queue<int> q;
for(auto v:lst){
int a = v.second.first;
int b = v.second.second;
// cout<<a<<" "<<b<<" => "<<gain<<endl;
if(gain<=a){
gain+=b;
ans++;
q.push(b);
}
else if(!q.empty() && q.top()>b){
gain -= q.top();q.pop();
gain += b;
q.push(b);
}
}
putr(ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
rush();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
21236 KB |
Output is correct |
2 |
Correct |
113 ms |
21248 KB |
Output is correct |
3 |
Correct |
112 ms |
21320 KB |
Output is correct |
4 |
Correct |
122 ms |
21320 KB |
Output is correct |
5 |
Correct |
115 ms |
21320 KB |
Output is correct |
6 |
Correct |
104 ms |
20812 KB |
Output is correct |
7 |
Correct |
110 ms |
19864 KB |
Output is correct |
8 |
Correct |
104 ms |
20684 KB |
Output is correct |
9 |
Correct |
102 ms |
20744 KB |
Output is correct |
10 |
Correct |
104 ms |
20820 KB |
Output is correct |
11 |
Correct |
104 ms |
22536 KB |
Output is correct |
12 |
Correct |
96 ms |
25732 KB |
Output is correct |
13 |
Correct |
114 ms |
22656 KB |
Output is correct |
14 |
Correct |
96 ms |
25748 KB |
Output is correct |
15 |
Correct |
95 ms |
25612 KB |
Output is correct |
16 |
Correct |
103 ms |
21004 KB |
Output is correct |
17 |
Correct |
112 ms |
20872 KB |
Output is correct |
18 |
Correct |
111 ms |
20888 KB |
Output is correct |
19 |
Correct |
115 ms |
20368 KB |
Output is correct |
20 |
Correct |
98 ms |
20428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
592 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
592 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
2 ms |
760 KB |
Output is correct |
29 |
Correct |
2 ms |
536 KB |
Output is correct |
30 |
Correct |
2 ms |
592 KB |
Output is correct |
31 |
Correct |
2 ms |
592 KB |
Output is correct |
32 |
Correct |
2 ms |
760 KB |
Output is correct |
33 |
Correct |
2 ms |
668 KB |
Output is correct |
34 |
Correct |
2 ms |
592 KB |
Output is correct |
35 |
Correct |
2 ms |
592 KB |
Output is correct |
36 |
Correct |
2 ms |
592 KB |
Output is correct |
37 |
Correct |
2 ms |
592 KB |
Output is correct |
38 |
Correct |
2 ms |
728 KB |
Output is correct |
39 |
Correct |
2 ms |
592 KB |
Output is correct |
40 |
Correct |
2 ms |
592 KB |
Output is correct |
41 |
Correct |
2 ms |
592 KB |
Output is correct |
42 |
Correct |
2 ms |
624 KB |
Output is correct |
43 |
Correct |
2 ms |
760 KB |
Output is correct |
44 |
Correct |
3 ms |
592 KB |
Output is correct |
45 |
Correct |
2 ms |
760 KB |
Output is correct |
46 |
Correct |
2 ms |
660 KB |
Output is correct |
47 |
Correct |
2 ms |
592 KB |
Output is correct |
48 |
Correct |
2 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
592 KB |
Output is correct |
50 |
Correct |
2 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
114 ms |
21236 KB |
Output is correct |
22 |
Correct |
113 ms |
21248 KB |
Output is correct |
23 |
Correct |
112 ms |
21320 KB |
Output is correct |
24 |
Correct |
122 ms |
21320 KB |
Output is correct |
25 |
Correct |
115 ms |
21320 KB |
Output is correct |
26 |
Correct |
104 ms |
20812 KB |
Output is correct |
27 |
Correct |
110 ms |
19864 KB |
Output is correct |
28 |
Correct |
104 ms |
20684 KB |
Output is correct |
29 |
Correct |
102 ms |
20744 KB |
Output is correct |
30 |
Correct |
104 ms |
20820 KB |
Output is correct |
31 |
Correct |
104 ms |
22536 KB |
Output is correct |
32 |
Correct |
96 ms |
25732 KB |
Output is correct |
33 |
Correct |
114 ms |
22656 KB |
Output is correct |
34 |
Correct |
96 ms |
25748 KB |
Output is correct |
35 |
Correct |
95 ms |
25612 KB |
Output is correct |
36 |
Correct |
103 ms |
21004 KB |
Output is correct |
37 |
Correct |
112 ms |
20872 KB |
Output is correct |
38 |
Correct |
111 ms |
20888 KB |
Output is correct |
39 |
Correct |
115 ms |
20368 KB |
Output is correct |
40 |
Correct |
98 ms |
20428 KB |
Output is correct |
41 |
Correct |
2 ms |
592 KB |
Output is correct |
42 |
Correct |
2 ms |
592 KB |
Output is correct |
43 |
Correct |
2 ms |
592 KB |
Output is correct |
44 |
Correct |
2 ms |
592 KB |
Output is correct |
45 |
Correct |
2 ms |
592 KB |
Output is correct |
46 |
Correct |
2 ms |
592 KB |
Output is correct |
47 |
Correct |
2 ms |
592 KB |
Output is correct |
48 |
Correct |
2 ms |
760 KB |
Output is correct |
49 |
Correct |
2 ms |
536 KB |
Output is correct |
50 |
Correct |
2 ms |
592 KB |
Output is correct |
51 |
Correct |
2 ms |
592 KB |
Output is correct |
52 |
Correct |
2 ms |
760 KB |
Output is correct |
53 |
Correct |
2 ms |
668 KB |
Output is correct |
54 |
Correct |
2 ms |
592 KB |
Output is correct |
55 |
Correct |
2 ms |
592 KB |
Output is correct |
56 |
Correct |
2 ms |
592 KB |
Output is correct |
57 |
Correct |
2 ms |
592 KB |
Output is correct |
58 |
Correct |
2 ms |
728 KB |
Output is correct |
59 |
Correct |
2 ms |
592 KB |
Output is correct |
60 |
Correct |
2 ms |
592 KB |
Output is correct |
61 |
Correct |
2 ms |
592 KB |
Output is correct |
62 |
Correct |
2 ms |
624 KB |
Output is correct |
63 |
Correct |
2 ms |
760 KB |
Output is correct |
64 |
Correct |
3 ms |
592 KB |
Output is correct |
65 |
Correct |
2 ms |
760 KB |
Output is correct |
66 |
Correct |
2 ms |
660 KB |
Output is correct |
67 |
Correct |
2 ms |
592 KB |
Output is correct |
68 |
Correct |
2 ms |
592 KB |
Output is correct |
69 |
Correct |
2 ms |
592 KB |
Output is correct |
70 |
Correct |
2 ms |
728 KB |
Output is correct |
71 |
Correct |
1 ms |
336 KB |
Output is correct |
72 |
Correct |
1 ms |
504 KB |
Output is correct |
73 |
Correct |
110 ms |
21656 KB |
Output is correct |
74 |
Correct |
118 ms |
21576 KB |
Output is correct |
75 |
Correct |
108 ms |
21832 KB |
Output is correct |
76 |
Correct |
106 ms |
21576 KB |
Output is correct |
77 |
Correct |
107 ms |
21576 KB |
Output is correct |
78 |
Correct |
108 ms |
22216 KB |
Output is correct |
79 |
Correct |
107 ms |
22216 KB |
Output is correct |
80 |
Correct |
117 ms |
22424 KB |
Output is correct |
81 |
Correct |
108 ms |
22420 KB |
Output is correct |
82 |
Correct |
111 ms |
22472 KB |
Output is correct |
83 |
Correct |
110 ms |
23836 KB |
Output is correct |
84 |
Correct |
112 ms |
23756 KB |
Output is correct |
85 |
Correct |
134 ms |
23960 KB |
Output is correct |
86 |
Correct |
110 ms |
23748 KB |
Output is correct |
87 |
Correct |
108 ms |
23836 KB |
Output is correct |
88 |
Correct |
105 ms |
26304 KB |
Output is correct |
89 |
Correct |
116 ms |
26304 KB |
Output is correct |
90 |
Correct |
111 ms |
26400 KB |
Output is correct |
91 |
Correct |
108 ms |
26312 KB |
Output is correct |
92 |
Correct |
109 ms |
26304 KB |
Output is correct |
93 |
Correct |
110 ms |
25980 KB |
Output is correct |
94 |
Correct |
110 ms |
26008 KB |
Output is correct |
95 |
Correct |
118 ms |
26048 KB |
Output is correct |
96 |
Correct |
119 ms |
26048 KB |
Output is correct |
97 |
Correct |
120 ms |
25864 KB |
Output is correct |
98 |
Correct |
118 ms |
21832 KB |
Output is correct |
99 |
Correct |
110 ms |
21832 KB |
Output is correct |
100 |
Correct |
123 ms |
21776 KB |
Output is correct |
101 |
Correct |
114 ms |
25536 KB |
Output is correct |
102 |
Correct |
106 ms |
25488 KB |
Output is correct |