아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Three Slices

시간 제한1초메모리 제한1024 MB

요약
양의 정수 배열과 한도 K가 주어질 때, 어떤 위치에서 시작하는 길이 M인 연속한 세 구간의 합이 각각 K 이하가 되는 가장 큰 M을 구한다.
난이도

보통10점 중 7점

유형
이분 탐색, 누적 합, 슬라이딩 윈도우, 배열
정답자
아직 제출이 없습니다

문제

You are given an array A_0A\_{0}, A_1A\_{1}, A_2A\_{2}, ...... , A_N−1A\_{N-1} of NN positive integers. Also, you are given an positive integer KK. Your task is to find the largest positive integer MM such that the following condition is satisfied:

  • There exists an integer 0≤i≤N−3M0 \le i \le N-3M such that

    1. ∑_j=ii+M−1A_j≤K\sum\_{j=i}^{i+M-1}A\_{j} \le K
    2. ∑_j=i+Mi+2M−1A_j≤K\sum\_{j=i+M}^{i+2M-1}A\_{j} \le K
    3. ∑_j=i+2Mi+3M−1A_j≤K\sum\_{j=i+2M}^{i+3M-1}A\_{j} \le K

입력

The first line contains two integers, NN and KK. The second line contains NN integers, the array AA given in order.

출력

Output a single positive integer denoting the largest possible MM. If there is no such MM, output 00.

제한

  • 1≤N≤5×1051 \le N \le 5 \times 10^{5}
  • 1≤K≤1091 \le K \le 10^{9}
  • 1≤A_i≤1091 \le A\_{i} \le 10^{9}

예제1

  1. 예제 1

    입력
    10 10
    3 7 4 3 1 3 5 2 5 1
    
    예상 출력
    2