제출 #1287516

#제출 시각아이디문제언어결과실행 시간메모리
1287516kutomei3쌀 창고 (IOI11_ricehub)C++20
100 / 100
8 ms1592 KiB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;

int besthub(int n, int k, int arr[], long long b)
{
  long long pfs[n + 1] = {0};
  for (int i = 1; i <= n; i++) pfs[i] = pfs[i - 1] + arr[i - 1];

  int r = 1, mx = 1;
  for (int i = 1; i <= n; i++) {
    while (r <= n) {
      if ((r - i + 1) & 1) {
        if (pfs[r] - pfs[(i + r) / 2 - 1] - pfs[(i + r) / 2] + pfs[i - 1] <= b) r++;
        else break;
      }
      else {
        if (pfs[r] - pfs[(i + r) / 2] - pfs[(i + r) / 2] + pfs[i - 1] <= b) r++;
        else break;
      }
    }
    mx = max(r - i, mx);
  }

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