Submission #6062

#TimeUsernameProblemLanguageResultExecution timeMemory
6062ainta스트랩 (JOI14_straps)C++98
55 / 100
4 ms1104 KiB
#pragma warning(disable:4996) #include<stdio.h> #include<algorithm> using namespace std; int n, w[2010], Res, Sum, S, m, Sr; int D[2010]; int main() { int i, a, b, j, x; scanf("%d", &n); for (i = 1; i < n; i++)D[i] = -2100000000; S++; for (i = 1; i <= n; i++){ scanf("%d%d", &a, &b); if (!a)w[++m] = b; else{ if (b >= 0){ Sum += b; S += a - 1; continue; } x = a - 1; for (j = n - 1; j >= 0; j--){ if (j + x < n && D[j + x] < D[j] + b)D[j + x] = D[j] + b; } } } sort(w + 1, w + m + 1); Res = Sum; for (j = 1; j <= m; j++){ Sr += w[m - j + 1]; if (S >= j){ if (Res < Sr + D[0] + Sum)Res = Sr + D[0] + Sum; } else{ if (Res < Sr + D[j - S] + Sum) Res = Sr + D[j - S] + Sum; } } printf("%d\n", Res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...