Submission #8216

#TimeUsernameProblemLanguageResultExecution timeMemory
8216baneling100스트랩 (JOI14_straps)C++98
5 / 100
0 ms1120 KiB
#include <stdio.h> #include <algorithm> #define INF 0x7fffffff using namespace std; int T, N, M, A[2001], B[2001][2], D[2001], Ans, Sum, Cnt=1; void input(void) { int i, X, Y; scanf("%d",&T); for(i=1 ; i<=T ; i++) { scanf("%d %d",&X,&Y); if(X) { if(Y>=0) { Sum+=Y; Cnt+=X-1; } else { B[++M][0]=X-1; B[M][1]=Y; } } else A[++N]=Y; } sort(A+1,A+N+1); for(i=N-1 ; i>=1 ; i--) A[i]+=A[i+1]; } void process(void) { int i, j; for(i=1 ; i<=T-1 ; i++) D[i]=-INF; for(i=1 ; i<=M ; i++) for(j=T-1 ; j>=B[i][0] ; j--) if(D[j]<D[j-B[i][0]]+B[i][1] && D[j-B[i][0]]!=-INF) D[j]=D[j-B[i][0]]+B[i][1]; for(i=T-2 ; i>=0 ; i--) if(D[i]<D[i+1]) D[i]=D[i+1]; Ans=Sum; for(i=1 ; i<=N ; i++) { if(i<=Cnt) { if(Ans<Sum+A[N-i+1]) Ans=Sum+A[N-i+1]; } else if(Ans<Sum+D[i-Cnt]+A[N-i+1]) Ans=Sum+D[i-Cnt]+A[N-i+1]; } } void output(void) { printf("%d",Ans); } int main(void) { input(); process(); output(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...