이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin (),v.end()
using namespace std;
int n,ans;
LL x[100005],pr[100005],s;
LL cost(int l,int r)
{
int m=(l+r)/2;
LL res=0;
res+=(pr[r]-pr[m])-((LL)(r-m)*x[m]);
l--;
res+=((LL)(m-l)*x[m])-(pr[m]-pr[l]);
//cout<<l<<" : "<<r<<" = "<<res<<endl;
return res;
}
bool check(LL k)
{
int l,r;
l=1;
r=k;
while(r<=n)
{
if(cost(l,r)<=s)
return 1;
l++;
r++;
}
return 0;
}
int besthub(int N,int L,int X[],LL B)
{
n=N;
s=B;
for(int i=1;i<=n;i++)
x[i]=X[i-1]-X[0]+1;
for(int i=1;i<=n;i++)
pr[i]=pr[i-1]+x[i];
int l,r,m;
l=1;
r=n;
cost(1,n);
while(l<=r)
{
m=(l+r)/2;
if(check(m))
{
l=m+1;
ans=m;
}
else
r=m-1;
}
return ans;
}
#ifdef death
int main()
{
int N,L,X[102];
LL B;
cin>>N>>L>>B;
for(int i=0;i<N;i++)
cin>>X[i];
cout<<besthub(N,L,X,B)<<endl;;
return 0;
}
#endif
/*
2
4 5
1 2
4+5+1
*/
# | 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... |