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;
#define int long long
const int INF = 1e15, MOD = 1e9 + 7;
mt19937_64 rnd(441225); // ddly
int binpow(int x, int a) {
int ret = 1;
while (a > 0) {
if (a & 1) {
ret *= x;
ret %= MOD;
a--;
} else {
x *= x;
x %= MOD;
a >>= 1;
}
}
return ret;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
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 + 1);
for (int i = 0; i < n; i++) {
int cnt = 1;
vector<int> ndp = dp;
while (cnt > 0 && k[i]-- > 0) {
cnt = 0;
for (int j = w[i]; j <= s; j++) {
if (dp[j - w[i]] + v[i] > dp[j]) {
cnt++;
ndp[j] = dp[j - w[i]] + v[i];
}
}
dp = ndp;
}
}
cout << dp[s];
}
# | 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... |