# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528851 | aSSSd | Rice Hub (IOI11_ricehub) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
return l+rng()%(r-l+1);
}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define iii pair<ii,int>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define mt make_tuple
#define getbit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define endl '\n'
#define all(v) v.begin(), v.end()
#define gg exit(0);
#define int long long
const int N = 1e5 + 100;
int n;
int a[N];
long long b;
int len;
int xuoi[N], ngc[N];
int f[N], g[N];
bool check(int mid)
{
long long cur = b;
int ret =0;
forinc(i,1,n)
{
if(i + mid - 1 > n) break;
int med = (i+i+mid)/2;
int lenn = mid/2;
if(mid&1)
{
int trc=xuoi[med+lenn-1]-f[med-1]*lenn- xuoi[med-1];
int sau=ngc[med-lenn+1]-g[med+1]*lenn- ngc[med+1];
if (trc + sau <= cur) return 1;
}
else
{
int trc = xuoi[med + lenn - 2] - f[med-1]*(lenn-1) - xuoi[med-1];
int sau = ngc[med-lenn+1] - g[med+1]*lenn - ngc[med+1];
if(trc + sau <= cur) return 1;
}
}
return 0;
}
main()
{
fasty;
// freopen("dbz.inp", "r", stdin);
//freopen("dbz.out", "w", stdout);
cin >> n >> len >> b;
forinc(i,1,n) cin >> a[i];
sort(a+1, a+n+1);
forinc(i,1,n-1)
{
f[i] = f[i-1] + a[i+1] - a[i];
xuoi[i] = xuoi[i-1] + f[i];
}
fordec(i,n,2)
{
g[i] = g[i+1] + a[i] - a[i-1];
ngc[i] = ngc[i+1] + g[i];
}
int l=1;
int res;
int r = n;
while(l <= r)
{
int mid = (l+r)/2;
if(check(mid))
{
res = mid;
l = mid+1;
}
else r = mid-1;
}
cout << res;
}