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 fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define deb(x) cout<<#x<<'='<<x<<'\n';
#define deb2(x,y) cout<<#x<<'='<<x<<", "<<#y<<'='<<y<<'\n';
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
const long double PI = acos(-1);
const int mod = 1e9 + 7;
signed main() {
fastio
int S, n; cin >> S >> n;
vector<pii> a;
for (int i = 0; i < n; i++) {
int v, w, k; cin >> v >> w >> k;
int cur = 0;
k = min(k, 2000);
while (cur + w <= S and k > 0) {
a.pb({w, v});
k--, cur += w;
}
}
n = sz(a);
int dp[S + 1] = {0};
for (int i = 1; i <= n; i++)
for (int j = S; j >= a[i - 1].f; j--)
dp[j] = max(dp[j], a[i - 1].s + dp[j - a[i - 1].f]);
cout << dp[S] << '\n';
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... |