#include <bits/stdc++.h>
using namespace std;
#define debug cout << "here\n";
#define ll long long
long long ans = 0;
ll v[1000003], w[1000003],k[1000003];
ll dp[2002][100003];
long long ns(int s, int idx){
if(s==0 || idx == 0)return 0;
else if(dp[s][idx] != -1) return dp[s][idx];
ll res = 0;
for(int i = 1; i <= k[idx]; i++){
if(s >= w[idx] * i)
res = max(res, ns(s-w[idx] * i, idx-1) + v[idx] * i);
else break;
}
res = max(res, ns(s,idx-1));
dp[s][idx] = res;
return res;
}
int main()
{
memset(dp,-1,sizeof(dp));
int s,n;
cin >> s>> n;
for(int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i];
cout << ns(s,n);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
112 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |