# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091504 | diponkinu | Knapsack (NOI18_knapsack) | C++14 | 84 ms | 4908 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 T = 2005;
vector<pair<int,int>> a[T];
int dp[T];
signed main(){
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
int n,s;
cin >> s >> n;
for(int i = 0; i < n; i++){
int v,w,k;
cin >> v >> w >> k;
a[w].push_back({v,k});
}
for(int i = 1; i <= T; i++ ){
// if(a[i].size()<1)continue;
sort(a[i].rbegin(), a[i].rend() );
// cout << a[i][0].first << " ";
int p = 0;
for(int j = 0; j < s/i; j++){
if(p>=a[i].size())break;
int tempvalue = a[i][p].first;
for(int o = s; o >= 0; o--){
if(o+i <= s)dp[o+i] = max(dp[o+i],dp[o] + tempvalue);
}
a[i][p].second--;
if(a[i][p].second == 0)p++;
}
}
cout << dp[s];
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... |