# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
436959 | 2021-06-25T11:39:48 Z | adamjinwei | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "ricehub.h" #define inf 1000000007 #define mod 1000000007 #define rnd() dist(rand_num) //#pragma GCC optimize("Ofast","inline","-ffast-math") //#pragma GCC target("avx,sse2,sse3,sse4,mmx") #define int long long using namespace std; unsigned seed=std::chrono::system_clock::now().time_since_epoch().count(); mt19937 rand_num(seed); uniform_int_distribution<int> dist(0,inf); template <typename T> void read(T &x){ x=0;char ch=getchar();int fh=1; while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();} while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); x*=fh; } template <typename T> void write(T x) { if (x<0) x=-x,putchar('-'); if (x>9) write(x/10); putchar(x%10+'0'); } template <typename T> void writeln(T x) { write(x); puts(""); } int n,m,b; int x[100005]; bool check(int mid) { if(mid==1) return b>=0; for(int l=1;l+mid-1<=n;++l) { int r=l+mid-1; if(mid%2==0) { int x1=(r+l-1)/2,x2=(r+l+1)/2; if(x[r]-x[x2-1]-x[x1]+x[l-1]<=b) return true; } else { int x1=(l+r)/2-1,x2=(l+r)/2+1; if(x[r]-x[x2-1]-x[x1]+x[l-1]<=b) return true; } } return false; } int besthub(int R,int L,int X[],int B) { n=R; m=L; b=B; for(int i=1;i<=n;++i) { x[i]=X[i-1]; x[i]+=x[i-1]; } int l=1,r=n; while(l<r) { int mid=l+r+1>>1; if(check(mid)) l=mid; else r=mid-1; } return l; }