Submission #104430

#TimeUsernameProblemLanguageResultExecution timeMemory
104430dfistricRice Hub (IOI11_ricehub)C++14
100 / 100
33 ms1792 KiB
#include <bits/stdc++.h> #include "ricehub.h" #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ll long long using namespace std; int besthub(int n, int L, int arr[], ll B) { int r = 1, m = 0; int a = 1, b = 0; ll sum = 0; int ma = 0; REP(l, n) { if ((r + l) / 2 > m) { sum = sum - b * (arr[m + 1] - arr[m]) + a * (arr[m + 1] - arr[m]); a++; b--; m++; } while (r < n) { //cout << l << " " << r << " " << m << " " << a << " " << b << " " << sum << endl; int rr = r + 1, aa = a, bb = b + 1; int mm = (rr + l) / 2; ll sum2 = sum + (arr[r] - arr[m]); if (mm > m) { sum2 = sum2 - bb * (arr[mm] - arr[m]) + aa * (arr[mm] - arr[m]); aa++; bb--; } if (sum2 <= B) { sum = sum2, r = rr, a = aa, b = bb, m = mm; } else { break; } } //cout << l << " " << r << " " << m << " " << a << " " << b << " " << sum << endl << endl; ma = max(ma, r - l); a--, sum -= (arr[m] - arr[l]); } return ma; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...