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
{
int ans=0;
for(int i=0;i<R;i++){
int count=1;long long cost=0;
int l=i-1,r=i+1;
while(X[i]==X[i+1]){
count++;
i++;
r++;
}
while(cost <= B ){
int ll=INT_MAX,rr=INT_MAX;
if(0<=l and cost+(X[i]-X[l])<=B)ll=(X[i]-X[l]);
if(r<R and cost+(X[r]-X[i])<=B)rr=(X[r]-X[i]);
if(ll<=rr and ll!=INT_MAX){
count++;
cost+=ll;
l--;
}
else if(rr<ll and rr!=INT_MAX){
count++;
cost+=rr;
r++;
}
else break;
}
ans=max(ans,count);
}
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... |