#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int S,n;
cin>>S>>n;
int V[n+1];
int W[n+1];
int K[n+1];
for(int i=1;i<=n;i++)cin>>V[i]>>W[i]>>K[i];
if(n==1){
cout<<min(K[1],S/W[1])*V[1];
return 0;
}
int ok=1;
for(int i=1;i<=n;i++)if(K[i]!=1)ok=0;
if(ok){
int dp[n+1][S+1];
for(int i=0;i<=n;i++)for(int j=0;j<=S;j++)dp[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=W[i];j<=S;j++){
dp[i][j]=max(dp[i][j],dp[i-1][j-W[i]]+V[i]);
}
}
int ans=0;
for(int i=1;i<=S;i++){
ans=max(ans,dp[n][i]);
}
cout<<ans;
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Incorrect |
0 ms |
456 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |