제출 #137870

#제출 시각아이디문제언어결과실행 시간메모리
137870zoooma13Cake 3 (JOI19_cake3)C++14
0 / 100
29 ms31736 KiB
#include <bits/stdc++.h> using namespace std; #define MAX_N 2003 #define INF 0x3f3f3f3f3f3f3f3f int n ,m; int c[MAX_N] ,v[MAX_N]; long long dp[MAX_N][MAX_N]; long long solve(int p ,int l){ if(l == 0) return -2LL*c[p-1]; if(p == n) return -INF; auto&ret = dp[p][l]; if(~ret) return ret; return ret = max(v[p]+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",&v[i],&c[i]); vector <int> ord(n); iota(ord.begin() ,ord.end() ,0); sort(ord.begin() ,ord.end() ,[](int&i ,int&j){ return c[i] < c[j]; }); vector <int> V(n) ,C(n); for(int i=0; i<n; i++) V[i] = v[ord[i]] ,C[i] = c[ord[i]]; for(int i=0; i<n; i++) v[i] = V[i] ,c[i] = C[i]; memset(dp ,-1 ,sizeof dp); long long ans = 0LL; for(int i=0; i<=n-m; i++) ans = max(ans ,solve(i+1 ,m-1)+v[i]+2*c[i]); printf("%I64d\n",ans); }

컴파일 시 표준 에러 (stderr) 메시지

cake3.cpp: In function 'int main()':
cake3.cpp:44:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
     printf("%I64d\n",ans);
                         ^
cake3.cpp:25: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:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v[i],&c[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...