제출 #129004

#제출 시각아이디문제언어결과실행 시간메모리
129004PlurmCake 3 (JOI19_cake3)C++11
0 / 100
3 ms380 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<pair<int,int> > pieces; long long query(int l, int r){ vector<int> v; for(int i = l; i <= r; i++){ v.push_back(pieces[i].first); } sort(v.begin(), v.end()); long long sum = 0ll; for(int i = 0; i < m-2; i++){ sum += 1ll * v.back(); v.pop_back(); } return sum; } long long solve(int l, int r, int lb, int rb){ int mid = (l + r)/2; long long ans = -1e18; int mindex = -1; for(int i = lb+1; i <= min(mid-m+2,rb); i++){ long long cur = query(i, mid-1) + 1ll * pieces[i-1].first + 1ll * pieces[mid].first + 2ll * pieces[i-1].second - 2ll * pieces[mid].second; if(cur > ans){ ans = cur; mindex = i; } } if(l <= mid-1) ans = max(ans, solve(l, mid-1, lb, mindex)); if(mid+1 <= r) ans = max(ans, solve(mid+1, r, mindex, rb)); return ans; } int main(){ scanf("%d%d",&n,&m); int v,c; for(int i = 0; i < n; i++){ scanf("%d%d",&v,&c); pieces.emplace_back(v,c); } stable_sort(pieces.begin(), pieces.end(), [](pair<int,int> x, pair<int,int> y){ return x.second < y.second; }); long long ans = solve(m-1,n-1,0,n-1); printf("%lld\n",ans); return 0; }

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

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