Submission #28883

#TimeUsernameProblemLanguageResultExecution timeMemory
28883inqrRice Hub (IOI11_ricehub)C++14
68 / 100
1000 ms5924 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...