Submission #533724

# Submission time Handle Problem Language Result Execution time Memory
533724 2022-03-07T04:23:09 Z Gurban Rice Hub (IOI11_ricehub) C++17
0 / 100
3 ms 588 KB
#include "bits/stdc++.h"
#include "ricehub.h"
using namespace std;

using ll = long long;

const int maxn=1e5+5;
ll p[maxn],b;
int a[maxn];

bool check(int l,int r){
  int md = (l + r) >> 1;
  ll val = 1ll * a[md] * (md - l);
  if(md-1 >= 0) val -= p[md-1];
  if(l-1 >= 0) val += p[l-1];

  val += p[r] - p[md];
  val -= 1ll * a[md] * (r - md);
  return (val <= b);
}

int besthub(int R, int L, int X[], long long B){

  // return 10;

  for(int i = 0;i < R;i++) a[i] = X[i];
  b = B;

  p[0] = X[0];
  for(int i = 1;i < R;i++) p[i] = p[i - 1] + X[i];

  int ans = 0;
  for(int i = 0;i < R;i++){
    int l = 0,r = i - 1,md,jg=i;
    while(l <= r){
      md = (l + r) >> 1;
      if(check(md,r)) jg=md,r=md-1;
      else l=md+1;
    }
    ans = max(ans,i-jg+1);
  }
  return ans;
}

// 5 20 6 1 2 10 12 14 3
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -