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;
struct item {
ll val, wt, k;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll s, n;
cin >> s >> n;
vector<bool> pos(s+1,0); pos[0] = 1;
vector<ll> v(s+1,0);
vector<item> it(n);
for(int i=0; i<n; i++) {
cin >> it[i].val >> it[i].wt >> it[i].k;
}
ll mx = 0;
for(ll i=0; i<n; i++) {
for(ll j=s-it[i].wt; j>=0; j--) {
if(pos[j]) {
ll cg = min(it[i].k,s);
for(ll m=1; m<=cg; m++) {
if(m*it[i].wt <= s) {
v[j+(m*it[i].wt)] = max(v[j+(m*it[i].wt)], v[j]+(m*it[i].val));
pos[j+(m*it[i].wt)] = 1;
}
else break;
}
}
}
}
for(int i=1; i<=s; i++) mx = max(mx,v[i]);
cout << mx << "\n";
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... |