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;
typedef long long ll;
int main(){
int s, n;
cin >> s >> n;
vector<int> val(s+1, -1);
val[0] = 0;
for (int i = 0; i < n; i++){
int v, w, k;
cin >> v >> w >> k;
k = min(k, s/w);
for (int j = s; j > -1; j--){
for (int x = 1; x * w <= j && x <= k; x++){
if (val[j-x*w] == -1) continue;
val[j] = max(val[j-x*w]+x*v, val[j]);
}
}
}
cout << (*max_element(val.begin(), val.end())) << endl;
}
# | 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... |