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;
int besthub(int R, int L, int X[], long long B)
// R toplam pirinc tarlasi sayisi
// L yolun uzunlugu
// X[] pirinc tarlalarinin kordinatlari
// B harciyabilecegin maksimum para
// optimal cozum her zaman bir tarlanin uzerinde
{
long long ans=0;
deque < int > opt;long long optcost=0;
for(int i=0;i<R;i++){
//printf("yeni merkez %d\n",X[i]);
if(i>0)optcost+=(X[i]-X[i-1])*opt.size();//merkez degisince hepsi artcak
//printf(" yeni optcost %lld\n",optcost);
opt.push_back(X[i]); //oldugum yer yeni merkez ekliyorun
while(X[i]==X[i+1]){// ayni yedeki tarlalari al
i++;
opt.push_back(X[i]);
}
ans=max(ans,(long long)opt.size());
//cout<<"opt : ";for(int j=0;j<opt.size();j++)cout<<opt[i]<<" ";cout<<endl;
while(optcost > B){// cost fazlaysa bastan cikar
optcost -=X[i]-opt.front();
opt.pop_front();
//cout<<"cikarma oldu opt : ";for(int j=0;j<opt.size();j++)cout<<opt[i]<<" ";cout<<endl;
}
ans=max(ans,(long long)opt.size());
}
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... |