Submission #137940

#TimeUsernameProblemLanguageResultExecution timeMemory
137940zoooma13Cake 3 (JOI19_cake3)C++14
0 / 100
35 ms31736 KiB
#include <bits/stdc++.h> using namespace std; #define MAX_N 2003 #define INF 0x3f3f3f3f3f3f3f3f #define c first #define v second int n ,m; pair<int ,int> piece[MAX_N]; long long dp[MAX_N][MAX_N]; long long solve(int p ,int l){ if(l == 0) return -2LL*piece[p-1].c; if(p == n) return -INF; auto&ret = dp[p][l]; if(~ret) return ret; return ret = max(piece[p].v+solve(p+1 ,l-1) ,solve(p+1 ,l)); } int main() { scanf("%d%d",&n,&m); assert(n < MAX_N); for(int i=0; i<n; i++) scanf("%d%d",&piece[i].v,&piece[i].c); sort(piece ,piece+n); memset(dp ,-1 ,sizeof dp); long long ans = 0LL; for(int i=0; i<n; i++) ans = max(ans ,solve(i+1 ,m-1)+piece[i].v+2LL*piece[i].c); printf("%lld\n",ans); }

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m); assert(n < MAX_N);
     ~~~~~^~~~~~~~~~~~~~
cake3.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&piece[i].v,&piece[i].c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...