#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]);
}
//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Incorrect |
0 ms |
5924 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
5924 KB |
Output is correct |
2 |
Correct |
0 ms |
5924 KB |
Output is correct |
3 |
Correct |
0 ms |
5924 KB |
Output is correct |
4 |
Incorrect |
0 ms |
5924 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |