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>
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int s, n; cin >> s >> n;
vector<int> values, weights;
for(int i = 0; i < n; ++i){
int v, w, k; cin >> v >> w >> k;
int count = 1;
while(k > 0){
int curcnt = min(count, k);
values.push_back(curcnt*v);
weights.push_back(curcnt*w);
k -= curcnt;
count <<= 1;
}
}
int items_cnt = values.size();
vector<int> dp(s+1, 0);
for(int i = 0; i < items_cnt; ++i){
for(int j = s; j >= weights[i]; --j){
dp[j] = max(dp[j], dp[j - weights[i]] + values[i]);
}
}
cout << dp[s];
return 0;
}
# | 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... |