# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1044387 | sanatp977 | Knapsack (NOI18_knapsack) | C++17 | 36 ms | 2976 KiB |
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;
using ll = long long;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int s,n; cin>>s>>n;
vector<pair<int,int>>arr[2001];
for(int i=0;i<n;i++){
int v,w; ll k;
cin>>v>>w>>k;
arr[w].push_back({v,k});
}
ll dp[2001]; memset(dp,0,sizeof dp); ll ans = 0;
for(int i=1;i<=s;i++){
sort(arr[i].begin(),arr[i].end(),greater<pair<int,ll>>());
int index = 0;
for(int j=0;j<s/i;j++){
if(index>=arr[i].size())break;
for(int x=s;x>=i;x--){
dp[x]=max(dp[x],dp[x-i]+arr[i][index].first);
ans=max(ans,dp[x]);
}
arr[i][index].second-=1;
if(arr[i][index].second==0)index++;
}
}
cout<<ans<<"\n";
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |