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>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e5+5;
int dp[N], cur[N];
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int S, n;
cin >> S >> n;
for (int i = 1; i <= n; i++){
int v, w, k;
cin >> v >> w >> k;
for (int j = 0; j <= S-w; j++){
if ((!j or dp[j]) and cur[j] < k and dp[j+w] < dp[j]+v){
dp[j+w] = dp[j]+v;
cur[j+w] = cur[j]+1;
}
}
for (int j = 0; j <= S; j++) cur[j] = 0;
}
cout << *max_element(dp+1,dp+S+1);
}
# | 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... |