Submission #805471

#TimeUsernameProblemLanguageResultExecution timeMemory
805471oscar1fCake 3 (JOI19_cake3)C++17
0 / 100
2 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define int long long using pii=pair<int,int>; string to_string(string s) { return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const int INFINI=(int)1000*1000*1000*1000*1000*1000; int nbPossi,tailleCol,prix,benef,rep; vector<pair<int,int>> possi; int somMax(int deb,int fin,int nbVal) { vector<pii> sousTab(possi.begin()+deb,possi.begin()+fin+1); sort(sousTab.begin(),sousTab.end(),[] (pii a,pii b){ return a.second>b.second; }); int somme=0; for (int i=0;i<nbVal;i++) { somme+=sousTab[i].second; } return somme; } int calcMeil(int deb,int fin) { return possi[deb].second+possi[fin].second-2*(possi[fin].first-possi[deb].first)+somMax(deb+1,fin-1,tailleCol-2); } void calc(int minDeb,int maxDeb,int minFin,int maxFin) { if (maxDeb<minDeb or maxFin<minFin) { return; } int deb=(minDeb+maxDeb)/2; pii record={-INFINI,-1}; for (int i=minFin;i<=maxFin;i++) { if (i>=deb+tailleCol-1) { record=max(record,{calcMeil(deb,i),i}); } } rep=max(rep,record.first); calc(minDeb,deb-1,minFin,record.second); calc(deb+1,maxDeb,record.second,maxFin); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>nbPossi>>tailleCol; for (int i=0;i<nbPossi;i++) { cin>>benef>>prix; possi.push_back({prix,benef}); } sort(possi.begin(),possi.end()); rep=-INFINI; calc(0,nbPossi-1,0,nbPossi-1); cout<<rep<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...