#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include "ricehub.h"
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
vector<ll>v;
ll money;
int n;
int getmid(int i,int size){
return i + size/2;
}
bool possible(int x){
ll cost = 0, parity = 1ll*((x-1)&1);
for(int i=1;i<=x;++i)
cost += abs(v[1+x/2]-v[i]);
if(cost<=money)return 1;
for(int i=2;i<=n-x+1;++i){
cost += v[i-1] - v[getmid(i-1,x)] + parity*(v[getmid(i,x)] - v[getmid(i-1,x)]) + v[i+x-1] - v[getmid(i,x)];
if(cost<=money)return 1;
}
return 0;
}
int besthub(int cnt, int mx, vector<int>x, ll b)
{
//binary search the answer, iterate over all starts
// nlogn.
// how to take the median? array already sorted, dumb
// just take middle element
// problem is to compute the total distance in interval.
// going from start in i from i+1, size j.
// update cost to v[j] - v[i+1+j/2] + (v[i+1+j/2]-v[i+j/2])*(j/2+1) - (v[i+1+j/2]-v[i+j/2])*(j/2-1) + v[j]-v[mid]
// cost += v[j] - v[i+1+j/2] + (v[i+1+j/2]-v[i+j/2])*!parity + v[j+i+1]-v[i+1+j/2]
// pretty adhoc huh
v.pb(0);
for(auto y:x)v.pb(1LL*y);money = b;n = cnt;
int l = 1, r = n, ans = 1;
while(l<=r){
int md = l + (r-l+1)/2;
if(possible(md))ans = md, l = md + 1;
else r = md - 1;
}
return ans;
}
// int main(){_
// int n,l;ll b;cin>>n>>l>>b;
// vector<int>x(n);for(auto& y:x)cin>>y;
// cout<<besthub(n,l,x,b)<<endl;
// }
Compilation message
ricehub.cpp: In function 'int besthub(int, int, std::vector<int>, long long int)':
ricehub.cpp:55:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
55 | for(auto y:x)v.pb(1LL*y);money = b;n = cnt;
| ^~~
ricehub.cpp:55:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
55 | for(auto y:x)v.pb(1LL*y);money = b;n = cnt;
| ^~~~~
/usr/bin/ld: /tmp/ccuKJIHT.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status