#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,abm,mmx,sse4.2,fma,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define PB push_back
#define sqr(a) ((a)*(a))
#define I insert
#define F first
#define S second
bool cmp(pair<int,int> const&a, pair<int,int> const&b) {
return make_pair(a.S, a.F) < make_pair(b.S, b.F);
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
vector<pair<int,int>> a(n);
for(int i=0; i<n; i++) cin>>a[i].S;
for(int i=0; i<n; i++) cin>>a[i].F;
sort(a.begin(), a.end());
if(a[0].F==a[n-1].F) {
sort(a.begin(), a.end(), cmp);
int ans = 0, cur = 0;
for(int i=0; i<n; i++) {
if(cur <= a[0].F) {
cur += a[i].S;
ans++;
}
else {
cout<<ans<<'\n';
return 0;
}
}
}
vector<int> dp(n+1, INT64_MAX);
dp[0] = 0;
for(int i=0; i<n; i++) {
for(int j=n; j>0; j--) {
dp[j] = min((dp[j-1]<=a[i].F)?(dp[j-1] + a[i].S):INT64_MAX, dp[j]);
}
}
for(int i=n; i>=0; i--) {
if(dp[i]!=INT64_MAX){
cout<<i<<'\n';
break;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
16948 KB |
Output is correct |
2 |
Correct |
178 ms |
16568 KB |
Output is correct |
3 |
Correct |
163 ms |
16924 KB |
Output is correct |
4 |
Correct |
168 ms |
16796 KB |
Output is correct |
5 |
Correct |
164 ms |
16964 KB |
Output is correct |
6 |
Correct |
161 ms |
15756 KB |
Output is correct |
7 |
Correct |
156 ms |
15192 KB |
Output is correct |
8 |
Correct |
155 ms |
15696 KB |
Output is correct |
9 |
Correct |
159 ms |
15944 KB |
Output is correct |
10 |
Correct |
159 ms |
15908 KB |
Output is correct |
11 |
Correct |
145 ms |
14928 KB |
Output is correct |
12 |
Correct |
151 ms |
14932 KB |
Output is correct |
13 |
Correct |
163 ms |
15064 KB |
Output is correct |
14 |
Correct |
144 ms |
14928 KB |
Output is correct |
15 |
Correct |
149 ms |
14924 KB |
Output is correct |
16 |
Correct |
158 ms |
15800 KB |
Output is correct |
17 |
Correct |
151 ms |
15680 KB |
Output is correct |
18 |
Correct |
168 ms |
15188 KB |
Output is correct |
19 |
Correct |
158 ms |
15424 KB |
Output is correct |
20 |
Correct |
182 ms |
14260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |