This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
int n, dp[500][500];
vector<int> a, b, x;
int f(int ind, int cur){
if(ind==n) return 0;
if(dp[ind][cur]!=-1) return dp[ind][cur];
if(cur<=b[x[ind]]) return dp[ind][cur]=max(f(ind+1, cur+a[x[ind]])+1, f(ind+1, cur));
return dp[ind][cur]=f(ind+1, cur);
}
int main(){
cin>>n;
x.resize(n); a.resize(n); b.resize(n);
for(auto &e:a) cin>>e;
for(auto &e:b) cin>>e;
iota(all(x), 0);
sort(all(x), [&](int l, int r){
return (b[l]-a[r]<min({b[l], b[r], b[r]-a[l]}));
});
memset(dp, -1, sizeof(dp));
cout<<f(0, 0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |