Submission #253344

#TimeUsernameProblemLanguageResultExecution timeMemory
253344eohomegrownappsHoliday (IOI14_holiday)C++14
23 / 100
5055 ms3148 KiB
#include"holiday.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll findMaxFrom(int n, int start, int d, int attraction[]){ //from start int numwalk = d/2; int numtake = d-numwalk; priority_queue<ll,vector<ll>,greater<ll>> pq; ll tot = 0; ll ans = 0; for (int i = start; i<=min(n-1,start+numwalk); i++){ tot+=attraction[i]; pq.push(attraction[i]); } if (numtake==numwalk&&start+numwalk<=n-1){ tot-=pq.top(); pq.pop(); } ans=max(ans,tot); int cur = start+numwalk; while (cur<n-1&&numtake>0&&numwalk<d){ //walk one more numtake--; numwalk++; cur++; tot+=attraction[cur]; pq.push(attraction[cur]); tot-=pq.top(); pq.pop(); tot-=pq.top(); pq.pop(); ans=max(ans,tot); } return ans; } ll findMaxAttraction(int n, int start, int d, int attraction[]) { int begprefix = start; int endprefix = n-1-start; if (endprefix<begprefix){ reverse(attraction,attraction+n); swap(begprefix,endprefix); } ll mx = 0; for (int i = 0; i<=start; i++){ mx=max(mx,findMaxFrom(n,i,d-(start-i),attraction)); } return mx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...