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>
#ifdef DEBUG
#include "../templates/debug.h"
#else
#define deb(x...)
#endif
using namespace std;
#define int long long
int dp[(int)1e5 + 100][(int)2e3 + 10];
signed main() {
iostream::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int s,n;cin >> s >> n;
vector<array<int,3>> items(n);
for(int i = 0;i<n;i++){
for(int j = 0;j<3;j++)cin >> items[i][j];
}
for(int i =0;i<n;i++){
for(int j = 1;j<=s;j++){
dp[i][j] = dp[i][j - 1];
if(i != 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if(j >= items[i][1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - items[i][1]] + items[i][0]);
}
}
cout << dp[n - 1][s] << "\n";
}
# | 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... |