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;
using ll = long long;
using pii = pair<int, int>;
#define all(x) begin(x), end(x)
#define pb push_back
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int S, N; cin >> S >> N;
vector<int> V(N+1, 0), W(N+1, 0), K(N+1, 0);
for(int i=1; i<=N; i++){
cin >> V[i] >> W[i] >> K[i];
K[i] = min(K[i], S/W[i]);
}
ll dp[N+1][S+1] = {};
for(int i=1; i<=N; i++){
for(int j=1; j<=S; j++){
dp[i][j] = dp[i-1][j];
for(int k=1; k<=K[i]; k++){
int w = k*W[i];
if(j>=w){
dp[i][j] = max(dp[i][j], dp[i-1][j-w]+k*V[i]);
}
}
}
}
cout << dp[N][S];
}
# | 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... |