#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define v vector
const int N = 1e6 + 111, mod = 1e9 + 7;
void solve() {
int n,s,k,a,b,c;
cin>>s>>n;
if(n==1){
cin>>a>>b>>c;
cout<<min(s/b,c)*a<<'\n';
return;
}
v<int>weight(n+1),value(n+1),itemCount(n+1);
for(int i=0;i<n;i++)cin>>value[i]>>weight[i]>>itemCount[i];
v<v<int>>dp(n+11,v<int>(s+11,0));
for(int i=0;i<=n;i++)dp[0][i]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=s;j++)
for(int x=0;x<=itemCount[i-1];x++)
if(j-x*weight[i-1]>=0)dp[i][j]=max(dp[i][j],value[i-1]*x+dp[i-1][j-x*weight[i-1]]);
cout<<dp[n][s];
}
signed main() {
// freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// int t;scanf("%lld",&t);while(t--)
solve();
}
Compilation message
knapsack.cpp: In function 'void solve()':
knapsack.cpp:7:11: warning: unused variable 'k' [-Wunused-variable]
7 | int n,s,k,a,b,c;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
6 |
Halted |
0 ms |
0 KB |
- |