제출 #1215901

#제출 시각아이디문제언어결과실행 시간메모리
1215901kunzaZa183쌀 창고 (IOI11_ricehub)C++20
0 / 100
0 ms320 KiB
#include "ricehub.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int besthub(int R, int L, int X[], long long B) {
  vector<ll> qsum(R);
  qsum[0] = X[0];
  for (int i = 1; i < R; i++) qsum[i] = qsum[i - 1] + X[i];

  auto qry = [&](int l, int r) {
    if (l == 0) return qsum[r];
    return qsum[r] - qsum[l - 1];
  };

  int maxans = 1;
  for (int i = 0; i < R; i++) {
    int l = 0, r = min(i, R - i - 1);

    while (l < r) {
      int mid = (l + r + 1) / 2;

      ll cost = 0;
      if (mid != 0) {
        cost = qry(i + 1, i + mid) - qry(i - mid, i - 1);
      } else {
        cost = 0;
      }

      if (cost <= B) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }

    ll cost = 0;
    if (l != 0) {
      cost = qry(i + 1, i + l) - qry(i - l, i - 1);
    } else {
      cost = 0;
    }

    if (cost <= B) maxans = max(maxans, 2 * l + 1);
  }

  for (int i = 0; i + 1 < R; i++) {
    int l = 1, r = min(i, R - i);

    while (l < r) {
      int mid = (l + r + 1) / 2;

      ll cost = 0;
      if (mid != 0) {
        cost = qry(i + 1, i + mid) - qry(i - mid + 1, i);
      } else {
        cost = 0;
      }

      if (cost <= B) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }

    ll cost = 0;
    if (l != 0) {
      cost = qry(i + 1, i + l) - qry(i - l + 1, i);
    } else {
      cost = 0;
    }

    if (cost <= B) maxans = max(maxans, 2 * l);
  }

  return maxans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...