Curfew | 프로그래밍의 벗 PivotOJ
PivotOJ

Curfew

시간 제한: 2000ms메모리 제한: 1024MB출처: MOOI 2017-18 finalBOJ 30741

문제

Instructors of Some Informatics School make students go to bed.

The house contains nn rooms, in each room exactly bb students were supposed to sleep. However, at the time of curfew it happened that many students are not located in their assigned rooms. The rooms are arranged in a row and numbered from 1 to nn. Initially, in ii-th room there are aia_i students. All students are currently somewhere in the house, therefore a1+a2++an=nba_1 + a_2 + \ldots + a_n = nb. Also pp instructors live in this house (p2p \leq 2).

The process of curfew enforcement is the following. One instructor starts near room 11 and moves toward room nn. If there is a second instructor, she starts near room nn and moves toward room 11. After processing current room, each instructor moves on to the next one. If there are two instructors they enter rooms and move simultaneously. If nn is odd and there are two instructors, then only the first instructor processes the middle room. When all rooms are processed, the process ends.

When an instructor processes a room, she counts the number of students in the room, then turns off the light, and locks the room. Also, if the number of students inside the processed room is not equal to bb, the instructors writes down the number of this room into her notebook (and turns off the light, and locks the room). Instructors are in a hurry (to prepare the study plan for the next day), so they don't care about who is in the room, but only about the number of students.

While instructors are inside the rooms, students can run between rooms that are not locked and not being processed. A student can run by at most dd rooms, that is she can move to a room with number that differs my at most dd. Also, after (or instead of) running each student can hide under a bed in a room she is in. In this case the instructor will not count her during the processing. In each room any number of students can hide simultaneously.

Formally, here is what's happening:

  • A curfew is announced, at this point in room ii there are aia_i students.
  • Each student can run to another room but not further than dd rooms away from her initial room, or stay in place. After that each student can optionally hide under a bed.
  • Instructors enter room 11 (and also room nn if p=2p=2), counts students there, and locks the room (after it no one can enter or leave this room).
  • Each student from rooms with numbers from 22 to nn (or to n1n - 1 if p=2p=2) can run to another room but not further than dd rooms away from her current room, or stay in place. Each student can optionally hide under a bed.
  • Instructor(s) move from room 11 to room 22 (and from room nn to room n1n - 1 if p=2p=2).
  • This process continues until all rooms are processed.

Let xix_i denote the number of rooms in which ii-th instructor counted the number of students different from bb. Students know that the principal will only listen to one complaint, therefore they want to minimize the maximum of numbers xix_i. Help them find this value if they use the optimal strategy.

입력

The first line contains four integers pp, nn, dd and bb (1p21 \le p \le 2, 2n1000002 \le n \le 100\,000, 1dn11 \le d \le n - 1, 1b100001 \le b \le 10\,000), the number of instructors, number of rooms in the house, running distance of a student, official number of students in a room.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \le a_i \le 10^9), ii-th of which stands for the number of students in the ii-th room before curfew announcement.

It is guaranteed that a1+a2++an=nba_1 + a_2 + \ldots + a_n = nb.

출력

Output one integer, the minimal possible value of the maximum of xix_i.

힌트

In the first sample students can run fast enough to reach their own rooms before the instructor enters room 11, thus the answer is 00.

In the second sample the instructor writes down at least one room into her notebook. One of the optimal strategies is the following: before the instructor enters room 11, 1010 students run from room 55 to room 22, 1010 students from room 55 to room 33, and 1010 students from room 55 to room 44. Then in rooms 22, 33, and 44 one student hides under a bed, in room 55 two students hide, and then students do nothing. This way only room 11 gets written down.

In the third sample the first three rooms are processed by the first instructor, and the last two are processed by the second instructor. One of the optimal strategies is the following: firstly three students run from room 55 to room 44, on the next stage two of them run to room 33, and one of those two hides under a bed. This way, the first instructor writes down room 22, and the second writes down nothing.

In the fourth sample one of the optimal strategies is the following: firstly all students in room 11 hide, all students from room 22 run to room 33. On the next stage one student runs from room 33 to room 44, and 55 students hide. This way, the first instructor writes down rooms 11 and 22, the second instructor writes down rooms 55 and 66.

예제

예제 1

입력
1 5 3 1
0 0 0 5 0
출력
0

예제 2

입력
1 5 3 10
5 1 1 1 42
출력
1

예제 3

입력
2 5 1 1
1 0 0 0 4
출력
1

예제 4

입력
2 6 1 2
3 8 0 1 0 0
출력
2
코드를 제출하려면 로그인하세요.