// #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;
bool cmp(pair<int,int> a, pair<int,int> b){
return a.second < b.second;
}
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;
}
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;
}
}
int mx = 0;
for(int i = 0; i<=n; i++){
// cout<<dp[n][i]<<" ";
if(dp[n][i] != inf) mx = i;
}
cout<<mx<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
84 ms |
8260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |