Submission #163200

#TimeUsernameProblemLanguageResultExecution timeMemory
163200TadijaSebez스트랩 (JOI14_straps)C++11
100 / 100
19 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=2050; int dp[N]; int main() { int n,a,b; scanf("%i",&n); for(int i=2;i<=n;i++) dp[i]=-1e9; vector<int> zero; int ans=0; for(int j=1;j<=n;j++) { scanf("%i %i",&a,&b); if(a==0) zero.pb(max(b,0)); else if(a==1) ans+=max(0,b); else { for(int i=n;i>=a;i--) dp[i]=max(dp[i],dp[i-a+1]+b); for(int i=n-1;i>=1;i--) dp[i]=max(dp[i],dp[i+1]); } } sort(zero.rbegin(),zero.rend()); int tmp=0,sol=0; for(int i=1;i<=n;i++) { if(zero.size()>=i) tmp+=zero[i-1]; sol=max(sol,tmp+dp[i]); } printf("%i\n",ans+sol); return 0; }

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:28:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(zero.size()>=i) tmp+=zero[i-1];
      ~~~~~~~~~~~^~~
straps.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
straps.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...