Submission #886908

#TimeUsernameProblemLanguageResultExecution timeMemory
886908Zero_OPRice Hub (IOI11_ricehub)C++14
17 / 100
58 ms3712 KiB
#include<bits/stdc++.h>

using namespace std;

#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))

template<class T> bool minimize(T& a, T b){
  if(a > b) return a = b, true;
  return false;
}

template<class T> bool maximize(T& a, T b){
  if(a < b) return a = b, true;
  return false;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int N = 1e5 + 5;

int n, lim, x[N]; ll c, s[N];

ll f(int l, int r){
  if(l == r) return 0;
  ll avg = (s[r] - s[l - 1]) / (r - l + 1);
  int pos = upper_bound(x + l, x + r + 1, avg) - x - 1;

  int halfLeft = pos - l + 1;
  int halfRight = r - l + 1 - halfLeft;
  return (1LL * halfLeft * avg - (s[pos] - s[l - 1])) + ((s[r] - s[pos]) - 1LL * halfRight * avg);
}

int besthub(int R, int L, int X[0], ll B){
    n = R, lim = L; c = B;
    for(int i = 0; i < n; ++i){
      x[i + 1] = X[i];
      s[i + 1] = s[i] + X[i];
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i){
      int l = 1, r = i, j = -1;
      while(l <= r){
        int mid = l + r >> 1;
        if(f(mid, i) <= c) j = mid, r = mid - 1;
        else l = mid + 1;
      }
      maximize(ans, i - j + 1);
    }
    return ans;
}

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int mid = l + r >> 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...