CF1324E.Sleeping Schedule

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vova had a pretty weird sleeping schedule. There are hh hours in a day. Vova will sleep exactly nn times. The ii -th time he will sleep exactly after aia_i hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is 00 ). Each time Vova sleeps exactly one day (in other words, hh hours).

Vova thinks that the ii -th sleeping time is good if he starts to sleep between hours ll and rr inclusive.

Vova can control himself and before the ii -th time can choose between two options: go to sleep after aia_i hours or after ai1a_i - 1 hours.

Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.

输入格式

The first line of the input contains four integers n,h,ln, h, l and rr ( 1n2000,3h2000,0lr<h1 \le n \le 2000, 3 \le h \le 2000, 0 \le l \le r < h ) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time.

The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai<h1 \le a_i < h ), where aia_i is the number of hours after which Vova goes to sleep the ii -th time.

输出格式

Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally.

输入输出样例

  • 输入#1

    7 24 21 23
    16 17 14 20 20 11 22

    输出#1

    3

说明/提示

The maximum number of good times in the example is 33 .

The story starts from t=0t=0 . Then Vova goes to sleep after a11a_1 - 1 hours, now the time is 1515 . This time is not good. Then Vova goes to sleep after a21a_2 - 1 hours, now the time is 15+16=715 + 16 = 7 . This time is also not good. Then Vova goes to sleep after a3a_3 hours, now the time is 7+14=217 + 14 = 21 . This time is good. Then Vova goes to sleep after a41a_4 - 1 hours, now the time is 21+19=1621 + 19 = 16 . This time is not good. Then Vova goes to sleep after a5a_5 hours, now the time is 16+20=1216 + 20 = 12 . This time is not good. Then Vova goes to sleep after a6a_6 hours, now the time is 12+11=2312 + 11 = 23 . This time is good. Then Vova goes to sleep after a7a_7 hours, now the time is 23+22=2123 + 22 = 21 . This time is also good.

首页