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 int
void solve() {
int s, n;
cin >> s >> n;
vector<int> dp(s+1, -1);
dp[0] = 0;
for (int i = 0; i < n; i++) {
int v, w, k, l;
cin >> v >> w >> k;
while(k > 0) {
l = log2(k);
if (l != 0) {
k -= (1<<l)-1;
} else {
k--;
l++;
}
for (int x = 0; x < l; x++) {
for (int j = s; j >= 0; j--) {
if (j-(1LL<<x)*w < 0) {
break;
}
if (dp[j-(1LL<<x)*w] != -1) {
dp[j] = max(dp[j], dp[j-(1LL<<x)*w]+(1LL<<x)*v);
}
}
}
}
}
int ans = 0;
for (int i : dp) {
ans = max(ans, i);
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# | 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... |