CF1324E.Sleeping Schedule
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vova had a pretty weird sleeping schedule. There are h hours in a day. Vova will sleep exactly n times. The i-th time he will sleep exactly after ai 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 0). Each time Vova sleeps exactly one day (in other words, h hours).
Vova thinks that the i-th sleeping time is good if he starts to sleep between hours l and r inclusive.
Vova can control himself and before the i-th time can choose between two options: go to sleep after ai hours or after ai−1 hours.
Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.
沃瓦的睡眠时间表非常奇怪。一天有 h 小时,沃瓦总共会睡 n 次。第 i 次睡觉,他会在上一次醒来后恰好经过 ai 小时才开始入睡。你可以假设故事开始时沃瓦正好刚醒来(初始时间为 0)。每次沃瓦的睡眠时长恰好为一整天(即 h 小时)。
沃瓦认为第 i 次睡觉是“良好的”,当且仅当他开始睡觉的时间落在区间 [l,r](含端点)内。
沃瓦可以自我调控,在第 i 次睡觉前,他可以从以下两种选项中任选其一:在上一次醒来后 ai 小时入睡,或在上一次醒来后 ai−1 小时入睡。
你的任务是:若沃瓦采取最优策略,他最多能获得多少次“良好的”睡眠?
输入格式
The first line of the input contains four integers n,h,l and r (1≤n≤2000,3≤h≤2000,0≤l≤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 n integers a1,a2,…,an (1≤ai<h), where ai is the number of hours after which Vova goes to sleep the i-th time.
输入的第一行包含四个整数 n,h,l 和 r(1≤n≤2000, 3≤h≤2000, 0≤l≤r<h)——分别表示 Vova 入睡的次数、一天中的小时数,以及优质睡眠时间所在的区间。
输入的第二行包含 n 个整数 a1,a2,…,an(1≤ai<h),其中 ai 表示 Vova 第 i 次入睡前所经历的小时数。
输出格式
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 3.
The story starts from t=0. Then Vova goes to sleep after a1−1 hours, now the time is 15. This time is not good. Then Vova goes to sleep after a2−1 hours, now the time is 15+16=7. This time is also not good. Then Vova goes to sleep after a3 hours, now the time is 7+14=21. This time is good. Then Vova goes to sleep after a4−1 hours, now the time is 21+19=16. This time is not good. Then Vova goes to sleep after a5 hours, now the time is 16+20=12. This time is not good. Then Vova goes to sleep after a6 hours, now the time is 12+11=23. This time is good. Then Vova goes to sleep after a7 hours, now the time is 23+22=21. This time is also good.
示例中“好时间”的最大数量为 3。
故事从 t=0 开始。随后,Vova 在 a1−1 小时后入睡,此时时间为 15。该时间不是“好时间”。接着,Vova 在 a2−1 小时后入睡,此时时间为 15+16=7。该时间也不是“好时间”。然后,Vova 在 a3 小时后入睡,此时时间为 7+14=21。该时间是“好时间”。接着,Vova 在 a4−1 小时后入睡,此时时间为 21+19=16。该时间不是“好时间”。然后,Vova 在 a5 小时后入睡,此时时间为 16+20=12。该时间不是“好时间”。接着,Vova 在 a6 小时后入睡,此时时间为 12+11=23。该时间是“好时间”。最后,Vova 在 a7 小时后入睡,此时时间为 23+22=21。该时间也是“好时间”。
输入解题思路,AI测评打分。不知道怎么写?