This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 2000
#define INF 0x7fffffff
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int dp[N + N + 1], dq[N + N + 1];
int n, i, s, t, ans;
scanf("%d", &n);
for (s = -n; s <= n; s++)
dp[n + s] = -INF;
dp[n + 1] = 0;
for (i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b), a--;
memcpy(dq, dp, (n * 2 + 1) * sizeof *dp);
for (s = -n; s <= n; s++) {
int x = dq[n + s];
if (x == -INF)
continue;
t = min(s + a, n);
dp[n + t] = max(dp[n + t], x + b);
}
}
ans = -INF;
for (s = 0; s <= n; s++)
ans = max(ans, dp[n + s]);
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
straps.c: In function 'main':
straps.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
straps.c:21:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%d", &a, &b), a--;
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |