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
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define vr(v) v.begin(),v.end()
#define rv(v) v.rbegin(),v.rend()
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
#define Davit cout.tie(NULL);
using namespace std;
//#include "algo/debug.h"
int main() {
int S, n;
cin >> S >> n;
vector<int> V(n), W(n), K(n);
for (int i = 0; i < n; i++) {
cin >> V[i] >> W[i] >> K[i];
}
vector<int> dp(S * n + 5, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < K[i]; j++) {
for (int k = S * n; k >= 0; k--) {
if (k - W[i] >= 0)dp[k] = max(dp[k], dp[k - W[i]] + V[i]);
}
}
}
int answer = 0;
for (int k = S; k >= 0; k--) {
answer = max(answer, dp[k]);
}
cout << answer << 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... |