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 tol(bi) (1ll<<((int)(bi)))
int main(){
int n;
cin>>n;
vector<pair<int,int>> arr(n);
for (int i = 0; i < n; ++i)
{
cin>>arr[i].second;
}
for (int i = 0; i < n; ++i)
{
cin>>arr[i].first;
}
if (n>5000){
cout<<"NO"<<endl;
return 0;
}
sort(arr.begin(), arr.end(), [&](pair<int,int> a, pair<int,int> b){
return (a.first+a.second)<(b.first+b.second);
});
map<int,int> dp[n];
function<int(int,int)> f = [&](int node, int val)->int{
if (node>=n) return 0;
if (dp[node].count(val)) return dp[node][val];
if (arr[node].first<val){
return dp[node][val]=f(node+1,val);
}
return dp[node][val]=max(f(node+1,val+arr[node].second)+1,f(node+1,val));
};
cout<<f(0,0)<<endl;
}
# | 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... |