Submission #558199

#TimeUsernameProblemLanguageResultExecution timeMemory
558199ngpin04Rice Hub (IOI11_ricehub)C++14
100 / 100
12 ms2524 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int N = 1e5 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); #include "ricehub.h" //#include "grader.cpp" long long s[N]; long long sum(int l, int r) { return s[r] - s[l - 1]; } int besthub(int n, int L, int a[], long long lim) { s[0] = a[0]; for (int i = 1; i < n; i++) s[i] = s[i - 1] + a[i]; int ans = 0; for (int r = 0, l = 0; r < n; r++) { while (true) { int mid = (l + r) >> 1; long long tot = 0; tot += sum(mid, r) - (long long) (r - mid + 1) * a[mid]; tot += (long long) (mid - l + 1) * a[mid] - sum(l, mid); if (tot <= lim) break; l++; } maxi(ans, r - l + 1); } 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...