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;
int const INF = numeric_limits<int>::max() / 2;
#define ll long long
string out = "";
bool hasCycles = false;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tiii tuple<int,int,int>
#define tiid tuple<double,int,int>
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int s, n;
cin >> s >> n;
vector<int> weight, value, amt;
weight = value = amt = vector<int>(n);
for (int i = 0; i < n; i++) {
cin >> value[i] >> weight[i] >> amt[i];
}
vector<ll> dp(s + 1);
for (int j = 0; j < n; j++) {
for (int i = s; i >= 0; i--) {
for (int k = 0; k < amt[j]; k++) {
if (weight[j] * (k + 1) > i) continue;
dp[i] = max(dp[i], dp[i - ((k + 1) * weight[j])] + value[j] * (k + 1));
}
}
}
ll ma = 0;
for (auto d : dp) {
ma = max(ma, d);
}
cout << ma;
}
# | 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... |