This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* author: b14ck_5m0k3 */
/* date: 30-08-2023 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1000000007;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int S, N;
cin >> S >> N;
vector<int> V(N), W(N), K(N);
for(int _ = 0; _ < N; _++) {
cin >> V[_] >> W[_] >> K[_];
}
vector<vector<int>> dp(N + 1, vector<int>(S + 1));
for(int i = 0; i < N; i++) {
dp[i + 1] = dp[i];
for(int j = 0; j <= S; j++) {
if(j + W[i] <= S) {
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
}
}
}
cout << dp[N][S] << endl;
}
# | 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... |