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 <iostream>
const int N = 2001;
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll dp[N][2]{};
int s, n, v[(int) 1e5], w[(int) 1e5], k[(int) 1e5];
cin >> s >> n;
for(int i = 0; i < n; ++i)
cin >> v[i] >> w[i] >> k[i];
for(int i = 0; i < n; ++i){
for(int j = 1; j <= k[i] && j * w[i] <= s; ++j)
for(int t = 1; t <= s; ++t)
if(t - j * w[i] >= 0)
dp[t][1] = max(dp[t][1], dp[t - j * w[i]][0] + j * v[i]);
for(int j = 0; j <= s; ++j)
dp[j][0] = dp[j][1];
}
cout << dp[s][0] << '\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... |