Submission #46856

#TimeUsernameProblemLanguageResultExecution timeMemory
46856ffresh스트랩 (JOI14_straps)C++17
100 / 100
13 ms760 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 2005,inf = -2e9-150; int dp[N]; pair<int,int> inp[N]; int main(){ //freopen("input.txt","r",stdin); int n; scanf("%d",&n); int a,b,ret=0; for(int i=0;i<N;++i)dp[i]= inf; dp[1]= 0; for(int i=0;i<n;++i){ scanf("%d%d",&inp[i].first,&inp[i].second); } sort(inp,inp+n,greater<pair<int,int> >()); for(int i=0;i<n;++i){ int x = inp[i].first-1, y = inp[i].second; if(x<0){ for(int j=1;j<=n;++j) if(dp[j]!=inf)dp[j-1]= max(dp[j-1],dp[j]+y); } else{ for(int j=n;j>=1;--j){ int nj = min(n,j+x); if(dp[j]!=inf) dp[nj]= max(dp[nj], dp[j] + y); } } } for(int i=0;i<=n;++i)ret= max(ret,dp[i]); printf("%d\n",ret); return 0; }

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:18:9: warning: unused variable 'a' [-Wunused-variable]
     int a,b,ret=0;
         ^
straps.cpp:18:11: warning: unused variable 'b' [-Wunused-variable]
     int a,b,ret=0;
           ^
straps.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
straps.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&inp[i].first,&inp[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...