Submission #1019608

#TimeUsernameProblemLanguageResultExecution timeMemory
1019608LuvidiRice Hub (IOI11_ricehub)C++17
0 / 100
1090 ms2652 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back int besthub(int n, int L, int X[], long long b) { ll a[n],ans,l=0,r=0,s=0; for(int i=0;i<n;i++)a[i]=X[i]; while(r+1<n&&s+a[r+1]-a[0]<=b){ r++; s+=a[r]-a[0]; } ans=r-l+1; for(int i=1;i<n;i++){ s-=(a[i]-a[i-1])*(r-i+1); s+=(a[i]-a[i-1])*(i-l); while(r>=i&&a[i]-a[l]>a[r]-a[i]){ s-=a[i]-a[l]; l++; } if(r<i){ l=r=i; s=0; } while(s>b){ if(r-1>=i&&(l==i||a[r-1]-a[i]<=a[i]-a[l+1])){ s-=a[r]-a[i]; r--; }else{ s-=a[i]-a[l]; l++; } } while(s<b&&(l||r+1<n)){ if(r+1<n&&(!l||a[r+1]-a[l]<=a[i]-a[l-1])){ if(s+a[r+1]-a[i]>b)break; r++; s+=a[r]-a[i]; }else{ if(s+a[i]-a[l-1]>b)break; l--; s+=a[i]-a[l]; } } ans=max(ans,r-l+1); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...