#include <bits/stdc++.h>
using namespace std;
const int MAXX = 1e5 + 5;
int s,n,v[MAXX],w[MAXX],dp[2001][MAXX],k[MAXX];
int main(){
cin >> s >> n;
for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i];
for (int i = 1; i <= s; i++){
for (int j = 0; j < n; j++){
if (i >= w[j]){
int num = 1;
while (num*w[j] <= i && num <= k[j]){
dp[i][j] = max(max(dp[i - num*w[j]][j - 1] + v[j]*num,dp[i][j]),max(dp[i - 1][j],dp[i][j - 1]));
num++;
}
}
}
}
cout << dp[s][n - 1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
9 ms |
12636 KB |
Output is correct |
3 |
Correct |
9 ms |
12636 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
11 ms |
12376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
9 ms |
12636 KB |
Output is correct |
3 |
Correct |
9 ms |
12636 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Incorrect |
11 ms |
12376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
9 ms |
12636 KB |
Output is correct |
7 |
Correct |
9 ms |
12636 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
11 ms |
12376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
3676 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
9 ms |
12636 KB |
Output is correct |
7 |
Correct |
9 ms |
12636 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Incorrect |
11 ms |
12376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |