This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------KarginDefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
//-------------------KarginConstants------------------\\
const int mod = 998244353;
const int inf = 1e9;
//-------------------KarginCode------------------------\\
const int N = 100005, M = 2005;
ll v[N], w[N], k[N];
ll dp[2][M];
void KarginSolve() {
ll s, n;
cin >> s >> n;
for (int i = 0; i < n;i++) {
cin >> v[i] >> w[i] >> k[i];
k[i] = min(k[i], s / w[i]);
}
int prev = 0, cur = 1;
for (int i = 0;i < n;i++) {
for (int j = s;j >= 0;j--) {
dp[cur][j] = dp[prev][j];
for (int x = 1;x <= k[i];x++) {
if (x * w[i] + j <= s) dp[cur][j + x * w[i]] = max(dp[cur][j + x * w[i]], dp[prev][j] + x * v[i]);
}
}
swap(cur, prev);
}
ll ans = 0;
for (int i = 0; i <= s;i++) ans = max(ans, dp[prev][i]);
cout << ans << '\n';
}
int main() {
//Usaco
Kargin;
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message (stderr)
knapsack.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
knapsack.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------KarginDefines--------------------\\
| ^
knapsack.cpp:22:1: warning: multi-line comment [-Wcomment]
22 | //-------------------KarginConstants------------------\\
| ^
knapsack.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginCode------------------------\\
| ^
# | 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... |