Noise Reduction

면접 대비

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

요약
연속한 온도 값을 크기 g의 묶음으로 나눠 각 묶음 평균의 내림값을 구할 때, 이웃한 평균 차이의 최댓값이 T 이하가 되는 최소 g를 찾는다.
난이도

보통10점 중 4점

유형
완전 탐색, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Monique is a climatologist who is analyzing the effects of climate change on weather patterns in Antarctica. She has compiled a set of NN high-precision temperature readings in nanokelvins using her world-leading thermal energy measurement system at McMurdo Station.

Unfortunately, there is a lot of noise in the data because the other scientists keep having snowball fights near Monique's equipment, and penguins waddle past and peck at the sensor. Monique has since moved the system to a better location, but she would like to recover as much climate data as possible from her original readings.

She has hired you to write a program that will reduce the noise level in her data while she builds an even better thermal energy measurement system.

The noise level of the dataset varies depending on the group size you choose. Given a group size gg, the noise level can be calculated as follows:

  1. Partition consecutive readings into groups of size gg. Discard any readings at the end of the dataset that would not form a group of size gg.
  2. Compute the average temperature for each of the groups. Round down to the nearest integer less than or equal to the average (the floor of the average).
  3. Calculate the noise level by determining the maximum difference between the averages of two adjacent groups. If there is only a single group, the noise level is 00.

Your task is to determine the smallest group size that causes the noise level of Monique's dataset to be less than or equal to the threshold TT. Note that the largest number you should output is N/2+1N/2 + 1 since with that size you will only be able to create a single group of size N/2+1N/2 + 1 which by definition will have no noise.

입력

The first line contains two space-separated integers, 1≤N≤10,0001 \leq N \leq 10\\,000 and 1≤T≤1,0001 \leq T \leq 1\\,000, the number of readings to follow, and the target noise threshold, respectively.

The next NN lines contain the readings, with each line containing a single reading, an integer in the range \[0,1,000,000,000]\[0, 1\\,000\\,000\\,000].

출력

Output a single integer, the smallest group size that ensures that the noise level of Monique's dataset is less than or equal to the threshold TT.

힌트

In Sample Input 11, with a group size of 22, the average for the first group (11 and 33) is 22, the average for the second group (44 and 22) is 33, and the average for the third group (88 and 11) is 44 because you always round down to the nearest integer. The rest of the data is discarded because you cannot create a group of size 22. The noise level of this input with a group size of 22 is 11 because the maximum difference between adjacent group averages is 11. This is less than or equal to the threshold of 11. Since using a group size of 11 would result in a noise level of 77, the lowest group size that satisfies the noise level threshold is 22.

In Sample Input 22, when using a group size of 22, the third group (11 and 11) has an average of 11. This causes the difference between the averages of the second and third groups to be 22, which is greater than the threshold of 11. So using a group size of 22 is not sufficient to satisfy the noise level threshold. A group size of 33 is sufficient because the first group's average is 22 (remember, always round down), and the second group's average is 11.

예제2

  1. 예제 1

    입력
    7 1
    1
    3
    4
    2
    8
    1
    4
    
    예상 출력
    2
    
  2. 예제 2

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