#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 5e5+10;
int N;
pll arr[mxn];
ll sum = 0;
priority_queue<ll,vector<ll>,less<ll>> pq;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 0;i<N;i++)cin>>arr[i].fs;
for(int i = 0;i<N;i++)cin>>arr[i].sc;
sort(arr,arr+N,[](pll a,pll b){return a.fs+a.sc<b.fs+b.sc;});
for(int i = 0;i<N;i++){
if(sum>arr[i].sc){
if(pq.top()>arr[i].fs){
sum -= pq.top();pq.pop();
sum += arr[i].fs;pq.push(arr[i].fs);
}
}
else{
pq.push(arr[i].fs);
sum += arr[i].fs;
}
}
cout<<pq.size()<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 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 |
111 ms |
17448 KB |
Output is correct |
2 |
Correct |
111 ms |
17832 KB |
Output is correct |
3 |
Correct |
108 ms |
17496 KB |
Output is correct |
4 |
Correct |
111 ms |
17508 KB |
Output is correct |
5 |
Correct |
109 ms |
17488 KB |
Output is correct |
6 |
Correct |
111 ms |
16856 KB |
Output is correct |
7 |
Correct |
101 ms |
15920 KB |
Output is correct |
8 |
Correct |
109 ms |
16684 KB |
Output is correct |
9 |
Correct |
105 ms |
16688 KB |
Output is correct |
10 |
Correct |
113 ms |
16820 KB |
Output is correct |
11 |
Correct |
96 ms |
17576 KB |
Output is correct |
12 |
Correct |
107 ms |
19912 KB |
Output is correct |
13 |
Correct |
95 ms |
17616 KB |
Output is correct |
14 |
Correct |
104 ms |
20908 KB |
Output is correct |
15 |
Correct |
96 ms |
20428 KB |
Output is correct |
16 |
Correct |
103 ms |
17108 KB |
Output is correct |
17 |
Correct |
103 ms |
17108 KB |
Output is correct |
18 |
Correct |
105 ms |
17076 KB |
Output is correct |
19 |
Correct |
124 ms |
16664 KB |
Output is correct |
20 |
Correct |
102 ms |
16612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
584 KB |
Output is correct |
23 |
Correct |
2 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
764 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
584 KB |
Output is correct |
30 |
Correct |
1 ms |
856 KB |
Output is correct |
31 |
Correct |
1 ms |
580 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
600 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 |
2 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
480 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 |
604 KB |
Output is correct |
47 |
Correct |
1 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 |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
1 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 |
111 ms |
17448 KB |
Output is correct |
22 |
Correct |
111 ms |
17832 KB |
Output is correct |
23 |
Correct |
108 ms |
17496 KB |
Output is correct |
24 |
Correct |
111 ms |
17508 KB |
Output is correct |
25 |
Correct |
109 ms |
17488 KB |
Output is correct |
26 |
Correct |
111 ms |
16856 KB |
Output is correct |
27 |
Correct |
101 ms |
15920 KB |
Output is correct |
28 |
Correct |
109 ms |
16684 KB |
Output is correct |
29 |
Correct |
105 ms |
16688 KB |
Output is correct |
30 |
Correct |
113 ms |
16820 KB |
Output is correct |
31 |
Correct |
96 ms |
17576 KB |
Output is correct |
32 |
Correct |
107 ms |
19912 KB |
Output is correct |
33 |
Correct |
95 ms |
17616 KB |
Output is correct |
34 |
Correct |
104 ms |
20908 KB |
Output is correct |
35 |
Correct |
96 ms |
20428 KB |
Output is correct |
36 |
Correct |
103 ms |
17108 KB |
Output is correct |
37 |
Correct |
103 ms |
17108 KB |
Output is correct |
38 |
Correct |
105 ms |
17076 KB |
Output is correct |
39 |
Correct |
124 ms |
16664 KB |
Output is correct |
40 |
Correct |
102 ms |
16612 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
584 KB |
Output is correct |
43 |
Correct |
2 ms |
600 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
1 ms |
604 KB |
Output is correct |
46 |
Correct |
2 ms |
764 KB |
Output is correct |
47 |
Correct |
1 ms |
600 KB |
Output is correct |
48 |
Correct |
1 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
584 KB |
Output is correct |
50 |
Correct |
1 ms |
856 KB |
Output is correct |
51 |
Correct |
1 ms |
580 KB |
Output is correct |
52 |
Correct |
1 ms |
604 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
1 ms |
604 KB |
Output is correct |
55 |
Correct |
2 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
600 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 |
2 ms |
604 KB |
Output is correct |
61 |
Correct |
2 ms |
600 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
480 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 |
604 KB |
Output is correct |
67 |
Correct |
1 ms |
604 KB |
Output is correct |
68 |
Correct |
2 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 |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
116 ms |
17628 KB |
Output is correct |
74 |
Correct |
123 ms |
17492 KB |
Output is correct |
75 |
Correct |
111 ms |
17744 KB |
Output is correct |
76 |
Correct |
114 ms |
17520 KB |
Output is correct |
77 |
Correct |
119 ms |
17716 KB |
Output is correct |
78 |
Correct |
123 ms |
18388 KB |
Output is correct |
79 |
Correct |
127 ms |
18288 KB |
Output is correct |
80 |
Correct |
111 ms |
18480 KB |
Output is correct |
81 |
Correct |
114 ms |
18500 KB |
Output is correct |
82 |
Correct |
110 ms |
18388 KB |
Output is correct |
83 |
Correct |
121 ms |
18896 KB |
Output is correct |
84 |
Correct |
111 ms |
18896 KB |
Output is correct |
85 |
Correct |
120 ms |
18860 KB |
Output is correct |
86 |
Correct |
113 ms |
18896 KB |
Output is correct |
87 |
Correct |
115 ms |
18784 KB |
Output is correct |
88 |
Correct |
113 ms |
21964 KB |
Output is correct |
89 |
Correct |
112 ms |
20776 KB |
Output is correct |
90 |
Correct |
111 ms |
20908 KB |
Output is correct |
91 |
Correct |
115 ms |
20780 KB |
Output is correct |
92 |
Correct |
112 ms |
22216 KB |
Output is correct |
93 |
Correct |
112 ms |
21804 KB |
Output is correct |
94 |
Correct |
111 ms |
21804 KB |
Output is correct |
95 |
Correct |
113 ms |
21196 KB |
Output is correct |
96 |
Correct |
115 ms |
20936 KB |
Output is correct |
97 |
Correct |
112 ms |
20544 KB |
Output is correct |
98 |
Correct |
111 ms |
17852 KB |
Output is correct |
99 |
Correct |
113 ms |
17768 KB |
Output is correct |
100 |
Correct |
112 ms |
17896 KB |
Output is correct |
101 |
Correct |
107 ms |
21452 KB |
Output is correct |
102 |
Correct |
118 ms |
21448 KB |
Output is correct |