#include <stdio.h>
#define N 1000
#define T 100
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int bb[N][T], dp[N][T][2];
int n, k, m, i, l, r, t, ans;
scanf("%d%d%d", &n, &k, &m), k--;
while (m--) {
int b;
scanf("%d%d%d", &i, &b, &t), i--, t--;
bb[i][t] += b;
}
for (i = 0; i < n; i++)
for (t = T - 2; t >= 0; t--)
bb[i][t] += bb[i][t + 1];
ans = 0;
for (l = k; l >= 0; l--)
for (r = k; r < n; r++)
for (t = T - 1; t >= 0; t--) {
if (l == r)
dp[r][t][0] = dp[r][t][1] = t == 0 ? bb[l][t] : -1;
else {
dp[r][t][0] = dp[r][t][1] = -1;
if (t >= 1) {
dp[r][t][0] = max(dp[r][t][0], dp[r][t - 1][0]);
dp[r][t][1] = max(dp[r][t][1], dp[r - 1][t - 1][1]);
}
if (t >= r - l) {
dp[r][t][0] = max(dp[r][t][0], dp[r][t - r - l][1]);
dp[r][t][1] = max(dp[r][t][1], dp[r - 1][t - r - l][0]);
}
if (dp[r][t][0] != -1)
dp[r][t][0] += bb[l][t];
if (dp[r][t][1] != -1)
dp[r][t][1] += bb[r][t];
}
ans = max(ans, max(dp[r][t][0], dp[r][t][1]));
}
printf("%d\n", ans);
return 0;
}
Compilation message
go.c: In function 'main':
go.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d%d%d", &n, &k, &m), k--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
go.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d%d%d", &i, &b, &t), i--, t--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
588 KB |
Output isn't correct |
2 |
Incorrect |
13 ms |
588 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Incorrect |
18 ms |
784 KB |
Output isn't correct |
5 |
Incorrect |
18 ms |
460 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
73 ms |
844 KB |
Output isn't correct |
8 |
Incorrect |
60 ms |
1100 KB |
Output isn't correct |
9 |
Incorrect |
17 ms |
588 KB |
Output isn't correct |
10 |
Incorrect |
36 ms |
972 KB |
Output isn't correct |