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;
}
sort(arr.begin(), arr.end(), [&](pair<int,int> a, pair<int,int> b){
return (a.first+a.second)<(b.first+b.second);
});
vector<int> val(n+1,-1);
val[0]=0;
for (int i = 0; i < n; i++){
for (int j = n-1; j >= 0; j--){
if (val[j]==-1) continue;
if (val[j]<=arr[i].first){
if (val[j+1]==-1) val[j+1]=val[j]+arr[i].second;
val[j+1]=min(val[j+1],val[j]+arr[i].second);
}
else break;
}
}
for (int i = n; i >= 0; i--){
if (val[i]!=-1){
cout<<i<<endl;
break;
}
}
}
# | 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... |