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>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 3e5 + 1;
int main(){
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int s, n; cin >> s >> n;
ll k[n + 1], v[n + 1], w[n + 1];
for(int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
}
ll dp[s + 1];
fill(dp, dp + s + 1, 0);
dp[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = s; j >= 0; j--){
ll cnt = -1;
for(int l = j; l >= 0; l -= w[i]){
cnt++;
if(cnt > k[i]) break;
dp[j] = max(dp[j], dp[l] + cnt * v[i]);
}
}
}
ll mx = 0;
for(int i = 1; i <= s; i++)
mx = max(mx, dp[i]);
cout << mx;
}
# | 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... |