Submission #589408

#TimeUsernameProblemLanguageResultExecution timeMemory
589408yutabiHoliday (IOI14_holiday)C++14
47 / 100
5039 ms15184 KiB
#include"holiday.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll subtask(int n, int start, int d, int attraction[]) { ll ans=attraction[0]; multiset <int> st; st.insert(attraction[0]); ll sum=attraction[0]; for(int i=1;i<n;i++) { sum+=attraction[i]; st.insert(attraction[i]); while(st.size()>d-i) { sum-=*(st.begin()); st.erase(st.begin()); } //printf("%lld\n",sum); ans=max(ans,sum); } return ans; } long long int findMaxAttraction(int n, int start, int d, int attraction[]) { if(d==0) { return 0; } if(start==0) { return subtask(n,start,d,attraction); } ll left_low[4*n]; ll left_high[4*n]; ll right_low[4*n]; ll right_high[4*n]; for(int i=0;i<=d;i++) { left_low[i]=left_high[i]=right_low[i]=right_high[i]=0; } multiset <int> st; for(int i=start-1;i>=0;i--) { st.insert(-attraction[i]); int j=1; ll sum=0; for(multiset <int>::iterator it=st.begin();it!=st.end();j++,it++) { sum+=-(*it); left_low[(start-i)+j]=max(left_low[(start-i)+j],sum); left_high[(start-i)*2+j]=max(left_high[(start-i)*2+j],sum); } } st.clear(); for(int i=start+1;i<n;i++) { st.insert(-attraction[i]); int j=1; ll sum=0; for(multiset <int>::iterator it=st.begin();it!=st.end();j++,it++) { sum+=-(*it); right_low[(i-start)+j]=max(right_low[(i-start)+j],sum); right_high[(i-start)*2+j]=max(right_high[(i-start)*2+j],sum); } } for(int i=1;i<4*n;i++) { left_low[i]=max(left_low[i],left_low[i-1]); left_high[i]=max(left_high[i],left_high[i-1]); right_low[i]=max(right_low[i],right_low[i-1]); right_high[i]=max(right_high[i],right_high[i-1]); } ll best=0; for(int i=0;i<=d;i++) { best=max(best,max(left_low[i]+right_high[d-i],left_high[i]+right_low[d-i])); } for(int i=0;i<d;i++) { best=max(best,max(left_low[i]+right_high[d-i-1]+attraction[start],left_high[i]+right_low[d-i-1]+attraction[start])); } return best; }

Compilation message (stderr)

holiday.cpp: In function 'll subtask(int, int, int, int*)':
holiday.cpp:32:24: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         while(st.size()>d-i)
      |               ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...