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>
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int,int,int> triad;
#define int long long
#define INF 1e9
int s,n,val,weight,occ;
vector<int> dp;
bool update(int value, int w){
bool useful = false;
for(int i = dp.size()-w-1; i >= 0; i--){
dp[i + w] = max(dp[i+w], dp[i] + value);
if(dp[i+w] == dp[i] + value){
useful = true;
}
}
return useful;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> s >> n;
dp.resize(s+1);
int mod = 1e9+7;
dp[0] = 0;
for(int i = 0; i < n; i++){
cin >> val >> weight >> occ;
bool help = true;
while(occ-- && help){
help = update(val,weight);
}
}
int ans = dp[s];
cout << ans;
return 0;
}
Compilation message (stderr)
knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:25:9: warning: unused variable 'mod' [-Wunused-variable]
25 | int mod = 1e9+7;
| ^~~
# | 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... |