Submission #284516

#TimeUsernameProblemLanguageResultExecution timeMemory
284516BasilhijazRice Hub (IOI11_ricehub)C++17
0 / 100
5 ms768 KiB
#include "ricehub.h" using namespace std; typedef long long ll; int besthub(int R, int L, int X[], long long B) { ll pre[R + 1]; int X2[R + 1]; X2[0] = 0; pre[0] = 0; for(int i = 1; i <= R; i++){ X2[i] = X[i - 1]; pre[i] = X2[i] + pre[i - 1]; } int lo = 0; int hi = R; while(lo < hi){ ll mid = (lo + hi + 1)/2; bool can = 0; for(int i = 1; i + mid - 1 <= R; i++){ ll sum = 0; ll nos = (i + i + mid - 1)/2; ll k1 = nos - i - 1; sum += X2[nos]*k1 - (pre[nos - 1] - pre[i - 1]); ll k2 = (i + i + mid - 1) - nos - 1; sum += (pre[i + i + mid - 1] - pre[nos]) - X2[nos]*k2; if(sum <= B){ can = 1; break; } } if(can){ lo = mid; } else{ hi = mid - 1; } } return lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...