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 ll long long
using namespace std;
int s, n, k, v, w, cw, cv;
ll dp[2010], ans;
vector<pair<int, int>> item;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> s >> n;
for(int i=0; i<n; i++) {
cin >> v >> w >> k;
k = min(k, s/w);
while(k--) {
item.push_back({w, v});
}
}
for(auto i: item) {
cw = i.first;
cv = i.second;
for(int j=s; j>=0; j--) {
if(dp[j] == 0 && j != 0) continue;
if(cw + j <= s) dp[cw+j] = max(dp[cw+j], dp[j]+cv);
}
}
for(int i=0; i<=s; i++) {
ans = max(ans, dp[i]);
}
cout << ans;
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... |