Submission #706324

#TimeUsernameProblemLanguageResultExecution timeMemory
706324jamezzzHoliday (IOI14_holiday)C++17
100 / 100
1649 ms6580 KiB
#include "holiday.h" #include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; #define maxn 100005 int n,s,d,a[maxn],cantake,lptr,rptr; ll ans,sm; multiset<ll> in,out; void fix(){ while(in.size()>cantake){ auto it=in.begin(); sm-=*it; out.insert(*it); in.erase(it); } while(in.size()<cantake&&!out.empty()){ auto it=--out.end(); sm+=*it; in.insert(*it); out.erase(it); } } void add(int x){ sm+=x; in.insert(x); fix(); } void rem(int x){ if(out.find(x)!=out.end()){ out.erase(out.find(x)); } else{ in.erase(in.find(x)); sm-=x; fix(); } } void dnc(int l,int r,int optl,int optr){ if(l>r||optl>optr)return; int m=(l+r)>>1; while(lptr<m)rem(a[lptr++]); while(m<lptr)add(a[--lptr]); while(rptr<optl-1)add(a[++rptr]); while(optl-1<rptr)rem(a[rptr--]); fix(); ll mx=-1;int best=0; for(int i=optl;i<=optr;++i){ add(a[i]); cantake=max(d-(s-m+i-m),0); fix(); if(sm>mx)best=i,mx=sm; } rptr=optr; ans=max(ans,mx); dnc(l,m-1,optl,best); dnc(m+1,r,best,optr); } void solve(){ in.clear();out.clear(); sm=cantake=0; lptr=1,rptr=s; for(int i=s;i>=1;--i){ add(a[i]); cantake=max(d-(s-i),0); fix(); ans=max(ans,sm); } dnc(1,s-1,s+1,n); } ll findMaxAttraction(int _n,int _s,int _d,int _a[]){ n=_n,s=_s+1,d=_d; ans=0; for(int i=1;i<=n;++i)a[i]=_a[i-1]; solve(); reverse(a+1,a+n+1); s=n-s+1; solve(); return ans; }

Compilation message (stderr)

holiday.cpp: In function 'void fix()':
holiday.cpp:15:17: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |  while(in.size()>cantake){
      |        ~~~~~~~~~^~~~~~~~
holiday.cpp:21:17: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |  while(in.size()<cantake&&!out.empty()){
      |        ~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...