# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650289 | ono_de206 | Knapsack (NOI18_knapsack) | C++14 | 126 ms | 4904 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;
#define int long long
const int mxn=1e5+10;
const int mxm=2010;
vector<pair<int,int>> lol[mxm];
int dp[2][mxm];
signed main(){
// freopen("feast.in","r",stdin);
// freopen("feast.out","w",stdout);
int s,n;
cin>>s>>n;
for(int i=0; i<n; i++){
int v,w,k;
cin>>v>>w>>k;
lol[w].push_back({v,k});
}
int st=1;
for(int i=1; i<=s; i++){
if(lol[i].empty()) continue;
st^=1;
sort(lol[i].rbegin(),lol[i].rend());
for(int j=1; j<=s; j++) dp[st][j]=dp[st^1][j];
for(int j=1; j<=s; j++){
int idx=0;
int now=1;
int hhe=0;
int cur=0;
while(now*i<=j && hhe<lol[i].size()){
cur+=lol[i][hhe].first;
if(dp[st^1][j-(now*i)]+cur>dp[st][j]){
dp[st][j]=dp[st^1][j-(now*i)]+cur;
}
now++;
idx++;
if(idx==lol[i][hhe].second){
hhe++;
idx=0;
}
}
}
}
int ans=0;
for(int i=1; i<=s; i++) ans=max(ans,dp[st][i]);
cout<<ans<<'\n';
return 0;
}
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... |