This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
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 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... |