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;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define fi first
// implementing official solution
// subtask 1,2,3
int R;
int const r=1e5+3;
int X[r];
ll pre[r];
ll B;
bool check(int len)
{
F0R(i,R)
{
int las = i+len-1;
if(las>=R)break;
int mid = (i+las)/2;
ll sumpos = pre[mid]-pre[i];
ll cur=X[mid]*(mid-i)-sumpos;
ll sumneg = pre[las+1]-pre[mid+1];
cur += sumneg-X[mid]*(las-mid);
if(cur<=B)
{
return 1;
}
}
return 0;
}
int besthub(int R1, int L, int X1[], ll B1){
R=R1;
pre[0]=0;
F0R(i,R)
{
X[i]=X1[i];
pre[i+1]=pre[i]+(ll)X[i];
}
B=B1;
int lef=1,rig=R;
int ans=-1;
while(lef<=rig)
{
int mid = (lef+rig)/2;
if(check(mid))
{
lef=mid+1;
ans=mid;
}
else
{
rig=mid-1;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |