// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
bool cmp(pair<int,int> a, pair<int,int> b){
return a.second+a.first < b.second+b.first;
}
void shuffle(vector<pair<int,int>>& v){
int n = v.size();
for(int i = 0; i<3*n; i++){
int a = rng()%n; int b = rng()%n;
swap(v[a],v[b]);
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin>>n;
vector<pair<int,int>> v(n); for(auto& i : v) cin>>i.first;
for(auto& i :v) cin>>i.second;
sort(v.begin(),v.end(),cmp);
// for(auto x : v) cout<<x.first<<" "<<x.second<<endl;
if(n > 5000){
int s = 0;
int ans = 0;
for(int i = 0; i<n; i++){
if(s <= v[i].second){
s+=v[i].first; ans++;
}
}
cout<<ans<<endl; return 0;
}
int mx = 0;
int MAXN = 1e8;
MAXN/=(n*n);
for(int _ = 0; _<1; _++){
vector<vector<int>> dp(n+1, vector<int>(n+1,inf));
dp[0][0] = 0;
for(int i = 1; i<=n; i++){
for(int j = 0; j<=n; j++){
dp[i][j] = dp[i-1][j];
// take i
if(!j) continue;
int act = dp[i-1][j-1];
if(act <= v[i-1].second) act+=v[i-1].first;
else continue;
dp[i][j] = min(dp[i][j],act);
// cerr<<i<<" "<<j<<" "<<dp[i-1][j-1]<<" "<<v[i-1].second<<" "<<v[i-1].first<<" "<<dp[i][j]<<endl;
}
}
for(int i = 0; i<=n; i++){
// cout<<dp[n][i]<<" ";
if(dp[n][i] != inf) mx = max(mx,i);
}
}
cout<<mx<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
8284 KB |
Output is correct |
2 |
Correct |
125 ms |
17232 KB |
Output is correct |
3 |
Correct |
127 ms |
17352 KB |
Output is correct |
4 |
Correct |
126 ms |
17236 KB |
Output is correct |
5 |
Correct |
127 ms |
17480 KB |
Output is correct |
6 |
Correct |
122 ms |
16316 KB |
Output is correct |
7 |
Correct |
127 ms |
16208 KB |
Output is correct |
8 |
Correct |
120 ms |
16464 KB |
Output is correct |
9 |
Correct |
133 ms |
16512 KB |
Output is correct |
10 |
Correct |
123 ms |
16316 KB |
Output is correct |
11 |
Correct |
109 ms |
15428 KB |
Output is correct |
12 |
Correct |
107 ms |
15444 KB |
Output is correct |
13 |
Correct |
106 ms |
15308 KB |
Output is correct |
14 |
Correct |
105 ms |
15436 KB |
Output is correct |
15 |
Correct |
114 ms |
15560 KB |
Output is correct |
16 |
Correct |
124 ms |
16020 KB |
Output is correct |
17 |
Correct |
126 ms |
15956 KB |
Output is correct |
18 |
Correct |
118 ms |
15824 KB |
Output is correct |
19 |
Correct |
119 ms |
15808 KB |
Output is correct |
20 |
Correct |
120 ms |
16008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
118 ms |
190360 KB |
Output is correct |
22 |
Correct |
90 ms |
193420 KB |
Output is correct |
23 |
Correct |
88 ms |
191772 KB |
Output is correct |
24 |
Correct |
91 ms |
192336 KB |
Output is correct |
25 |
Correct |
92 ms |
192332 KB |
Output is correct |
26 |
Correct |
93 ms |
190288 KB |
Output is correct |
27 |
Correct |
92 ms |
194656 KB |
Output is correct |
28 |
Correct |
88 ms |
188828 KB |
Output is correct |
29 |
Correct |
91 ms |
192596 KB |
Output is correct |
30 |
Correct |
95 ms |
195988 KB |
Output is correct |
31 |
Correct |
99 ms |
195668 KB |
Output is correct |
32 |
Correct |
91 ms |
190016 KB |
Output is correct |
33 |
Correct |
94 ms |
192848 KB |
Output is correct |
34 |
Correct |
90 ms |
194628 KB |
Output is correct |
35 |
Correct |
92 ms |
193876 KB |
Output is correct |
36 |
Correct |
99 ms |
194900 KB |
Output is correct |
37 |
Correct |
90 ms |
191012 KB |
Output is correct |
38 |
Correct |
90 ms |
189780 KB |
Output is correct |
39 |
Correct |
91 ms |
193272 KB |
Output is correct |
40 |
Correct |
92 ms |
191020 KB |
Output is correct |
41 |
Correct |
93 ms |
194900 KB |
Output is correct |
42 |
Correct |
91 ms |
191056 KB |
Output is correct |
43 |
Correct |
92 ms |
190688 KB |
Output is correct |
44 |
Correct |
95 ms |
193364 KB |
Output is correct |
45 |
Correct |
93 ms |
192008 KB |
Output is correct |
46 |
Correct |
92 ms |
195668 KB |
Output is correct |
47 |
Correct |
95 ms |
192280 KB |
Output is correct |
48 |
Correct |
92 ms |
191824 KB |
Output is correct |
49 |
Correct |
90 ms |
190292 KB |
Output is correct |
50 |
Correct |
96 ms |
192760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 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 |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
123 ms |
8284 KB |
Output is correct |
22 |
Correct |
125 ms |
17232 KB |
Output is correct |
23 |
Correct |
127 ms |
17352 KB |
Output is correct |
24 |
Correct |
126 ms |
17236 KB |
Output is correct |
25 |
Correct |
127 ms |
17480 KB |
Output is correct |
26 |
Correct |
122 ms |
16316 KB |
Output is correct |
27 |
Correct |
127 ms |
16208 KB |
Output is correct |
28 |
Correct |
120 ms |
16464 KB |
Output is correct |
29 |
Correct |
133 ms |
16512 KB |
Output is correct |
30 |
Correct |
123 ms |
16316 KB |
Output is correct |
31 |
Correct |
109 ms |
15428 KB |
Output is correct |
32 |
Correct |
107 ms |
15444 KB |
Output is correct |
33 |
Correct |
106 ms |
15308 KB |
Output is correct |
34 |
Correct |
105 ms |
15436 KB |
Output is correct |
35 |
Correct |
114 ms |
15560 KB |
Output is correct |
36 |
Correct |
124 ms |
16020 KB |
Output is correct |
37 |
Correct |
126 ms |
15956 KB |
Output is correct |
38 |
Correct |
118 ms |
15824 KB |
Output is correct |
39 |
Correct |
119 ms |
15808 KB |
Output is correct |
40 |
Correct |
120 ms |
16008 KB |
Output is correct |
41 |
Correct |
118 ms |
190360 KB |
Output is correct |
42 |
Correct |
90 ms |
193420 KB |
Output is correct |
43 |
Correct |
88 ms |
191772 KB |
Output is correct |
44 |
Correct |
91 ms |
192336 KB |
Output is correct |
45 |
Correct |
92 ms |
192332 KB |
Output is correct |
46 |
Correct |
93 ms |
190288 KB |
Output is correct |
47 |
Correct |
92 ms |
194656 KB |
Output is correct |
48 |
Correct |
88 ms |
188828 KB |
Output is correct |
49 |
Correct |
91 ms |
192596 KB |
Output is correct |
50 |
Correct |
95 ms |
195988 KB |
Output is correct |
51 |
Correct |
99 ms |
195668 KB |
Output is correct |
52 |
Correct |
91 ms |
190016 KB |
Output is correct |
53 |
Correct |
94 ms |
192848 KB |
Output is correct |
54 |
Correct |
90 ms |
194628 KB |
Output is correct |
55 |
Correct |
92 ms |
193876 KB |
Output is correct |
56 |
Correct |
99 ms |
194900 KB |
Output is correct |
57 |
Correct |
90 ms |
191012 KB |
Output is correct |
58 |
Correct |
90 ms |
189780 KB |
Output is correct |
59 |
Correct |
91 ms |
193272 KB |
Output is correct |
60 |
Correct |
92 ms |
191020 KB |
Output is correct |
61 |
Correct |
93 ms |
194900 KB |
Output is correct |
62 |
Correct |
91 ms |
191056 KB |
Output is correct |
63 |
Correct |
92 ms |
190688 KB |
Output is correct |
64 |
Correct |
95 ms |
193364 KB |
Output is correct |
65 |
Correct |
93 ms |
192008 KB |
Output is correct |
66 |
Correct |
92 ms |
195668 KB |
Output is correct |
67 |
Correct |
95 ms |
192280 KB |
Output is correct |
68 |
Correct |
92 ms |
191824 KB |
Output is correct |
69 |
Correct |
90 ms |
190292 KB |
Output is correct |
70 |
Correct |
96 ms |
192760 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Incorrect |
133 ms |
17620 KB |
Output isn't correct |
74 |
Halted |
0 ms |
0 KB |
- |