Submission #302368

#TimeUsernameProblemLanguageResultExecution timeMemory
302368UserIsUndefinedRice Hub (IOI11_ricehub)C++14
0 / 100
21 ms1792 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; int besthub(int R, int L, int X[], long long B) { int low = 0; int high = R*2; while(low < high){ int mid = (high+low)/2; // cout << mid << " " << low << " " << high << endl; long long sum = 0; long long now = X[mid/2]; long long pluss = mid - mid/2 - 1; long long mines = mid - pluss + 1; for (int i = 0 ; i < mid ; i++){ sum+= llabs(now - X[i]); } if (sum <= B){ low = mid + 1; continue; } int good = false; for (int i = now + 1 ; i + pluss < R ; i++){ int bye = X[i - mines]; sum-= llabs(X[i-1] - bye); int hello = X[i + pluss]; sum+= llabs(X[i] - hello); sum+= llabs(X[i] - X[i-1])*mines; sum-= llabs(X[i] - X[i-1])*(pluss - 1); if (sum <= B){ low = mid + 1; good = true; break; } } if (good)continue; high = mid - 1; } return low - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...