#include<bits/stdc++.h>
#include "ricehub.h"
#include<ext/pb_ds/assoc_container.hpp>
/**zagaro & lauren <3**/
#define mod 1000000007 //1e9 + 7
#define pi acos(-1)
#define wl while
#define str string
#define ENDL "\n"
#define sal ' '
#define tp_set ll
#define prc(n) cout.precision(n);cout<<fixed;
#define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef bool bl;
typedef char car;
using namespace std;
using namespace __gnu_pbds;
int besthub(int R, int L, int X[], long long M){
ll a, b, x, y, l, r, m;
vector<ll> prf(R+1, 0);
for(int i=1;i<=R;i++)prf[i] = prf[i-1]+X[i-1];
l=1;r=R+1;
bl B;
wl(l < r-1){
m = (l+r)/2;
B = false;
a=0;b=m;
for(int i=(m+1)/2;b<=R;i++){
x = (X[i-1]*(i-1-a)-(prf[i-1]-prf[a]))+((prf[b]-prf[i])-X[i-1]*(b-i));
if(x <= M){
B=true;
break;
}
a++;b++;
}
if(B)l=m;
else r=m;
}
return l;
}
| # | 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... |