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 "ricehub.h"
#include<bits/stdc++.h>
using namespace std;
long long int typedef li;
int besthub(int n, int m, int x[], li b)
{
int mx=0; li balans=0;
int l=0,r=0;
for (int i=0;i<n;i++) if (balans+(x[i]-x[0])<=b) balans+=(x[i]-x[0]),r++;
//cout<<0<<": "<<"["<<l<<","<<r<<") - "<<balans<<endl;
for (int i=1;i<n;i++)
{
balans+=(li)(i-l)*(x[i]-x[i-1]);
balans-=(li)(r-i)*(x[i]-x[i-1]);
//cout<<i<<": "<<"["<<l<<","<<r<<") - "<<balans<<endl;
while (balans>b) balans-=(x[i]-x[l]),l++;
while (r<n && balans+(x[r]-x[i])<=b) balans+=(x[r]-x[i]),r++;
mx=max(mx,r-l);
//cout<<i<<": "<<"["<<l<<","<<r<<") - "<<balans<<endl;
//cout<<endl;
}
return mx;
}
/*
5 20 6
1
2
10
12
14
3
*/
# | 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... |