# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
655225 | 2022-11-03T14:55:48 Z | Trumling | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include "ricehub.h" #include<iostream> #include<cmath> using namespace std; typedef long long ll; #define pb push_back #define F first #define S second #define enter cout<<'\n'; int besthub(int R, int L, int X[], long long B) { ll ans=1; ll plus=R; while(plus!=1) { if(ans!=1) break; bool pre=false; ll curr=0; //cout<<'\n'; for(int i=0;i<=R-plus;i++) { ll med; if(!pre) { med=(i+i+plus)/2; for(int j=i;j<i+plus;j++) curr+=abs(X[med]-X[j]); pre=true; } else { curr-=abs(X[i-1]-X[med]); med++; ll dif=abs(X[med]-X[med-1]); curr=curr+abs(i-med)*dif; curr=curr-(plus-med+1)*dif; curr+=abs(X[med]-X[i+plus-1]); curr-=abs(X[med-1]-x[i-1]); } //cout<<curr<<' '; if(curr<=B) { ans=plus; break; } } plus--; } //cout<<'\n'<<ans<<'\n'; return ans; }