제출 #1124936

#제출 시각아이디문제언어결과실행 시간메모리
1124936sleepntsheep스트랩 (JOI14_straps)C11
55 / 100
6 ms444 KiB
#include <stdio.h> #include <limits.h> #define N 2000 int n, a[N], b[N], o, p, ii[N], jj[N], rity; long long dp[N + 1], ans, ans2, ans3, run; int main() { int i, j, k; scanf("%d", &n); rity = 1; for (i = 0; i < n; ++i) { scanf("%d%d", a + i, b + i); if (b[i] >= 0) { if (a[i]) { ans += b[i]; rity += a[i] - 1; } else jj[p++] = i; } } for (i = 1; i < n; ++i) dp[i] = -2e12; dp[0] = 0; for (i = 0; i < n; ++i) { if (b[i] < 0) { --a[i]; if (a[i] <= 0) continue; for (j = p; j >= a[i]; --j) { if (dp[j] < dp[j - a[i]] + b[i]) dp[j] = dp[j - a[i]] + b[i]; } } } for (j = 0; j < p; ++j) for (i = 1; i < p; ++i) { if (b[jj[i - 1]] < b[jj[i]]) { k = jj[i]; jj[i] = jj[i - 1]; jj[i - 1] = k; } } for (i = 0; i < rity && i < p; ++i) ans += b[jj[i]]; for (i = rity; i < p; ++i) { run += b[jj[i]]; ans3 = dp[i - rity + 1] + run; if (ans3 > ans2) ans2 = ans3; } printf("%lld", ans + ans2); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

straps.c: In function 'main':
straps.c:11:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%d", &n);
      |   ^~~~~~~~~~~~~~~
straps.c:15:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d", a + i, b + i);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...