CF847D.Dog Show

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!

On the show a dog needs to eat as many bowls of dog food as possible (bottomless stomach helps here). Dogs compete separately of each other and the rules are as follows:

At the start of the show the dog and the bowls are located on a line. The dog starts at position x = 0 and n bowls are located at positions x = 1, x = 2, ..., x = n. The bowls are numbered from 1 to n from left to right. After the show starts the dog immediately begins to run to the right to the first bowl.

The food inside bowls is not ready for eating at the start because it is too hot (dog's self-preservation instinct prevents eating). More formally, the dog can eat from the i-th bowl after t__i seconds from the start of the show or later.

It takes dog 1 second to move from the position x to the position x + 1. The dog is not allowed to move to the left, the dog runs only to the right with the constant speed 1 distance unit per second. When the dog reaches a bowl (say, the bowl i), the following cases are possible:

  • the food had cooled down (i.e. it passed at least t__i seconds from the show start): the dog immediately eats the food and runs to the right without any stop,
  • the food is hot (i.e. it passed less than t__i seconds from the show start): the dog has two options: to wait for the i-th bowl, eat the food and continue to run at the moment t__i or to skip the i-th bowl and continue to run to the right without any stop.

After T seconds from the start the show ends. If the dog reaches a bowl of food at moment T the dog can not eat it. The show stops before T seconds if the dog had run to the right of the last bowl.

You need to help your dog create a strategy with which the maximum possible number of bowls of food will be eaten in T seconds.

一档全新的狗狗选秀节目将于下周在电视上开播。节目中,狗狗需要展现“无底胃”、战略思维以及自我保护本能。你和你的爱犬受邀与其他参赛者同台竞技,而你自然希望赢得冠军!

在节目中,狗狗需尽可能多地吃掉狗粮碗中的食物(“无底胃”在此大显身手)。所有狗狗独立参赛,规则如下:

节目开始时,狗狗与狗粮碗均位于一条直线上。狗狗起始于位置 x=0x = 0,而 nn 个狗粮碗则分别位于位置 x=1, x=2, …, x=nx = 1,\, x = 2,\, \dots,\, x = n。这些碗从左至右依次编号为 11 至 nn。节目一开始,狗狗立即向右奔跑,直奔第一个碗。

由于刚出锅的食物温度过高(狗狗的自我保护本能阻止其进食),碗中食物在节目开始时尚不可食用。更准确地说:狗狗只能在节目开始后 至少 tit_i 秒,才可食用第 ii 个碗中的食物。

狗狗每秒沿直线向右移动一个单位距离(即从位置 xx 到 x+1x+1 需耗时 1 秒)。狗狗不允许向左移动,只能以恒定速度 11 单位距离/秒持续向右奔跑。当狗狗抵达某个碗(例如第 ii 个碗)时,可能出现以下两种情形:

  • 食物已冷却(即自节目开始起已过去 至少 tit_i 秒):狗狗立即进食,并毫不停顿地继续向右奔跑;
  • 食物仍过热(即自节目开始起尚不足 tit_i 秒):狗狗有两种选择——
    (1)在第 ii 个碗处等待,直至时刻 tit_i 再进食,随后继续向右奔跑;
    (2)直接跳过第 ii 个碗,毫不停顿地继续向右奔跑。

节目在开始后 TT 秒准时结束。若狗狗恰好于时刻 TT 抵达某只碗,则不得进食。若狗狗在 TT 秒前已越过最后一个碗(即跑至 x>nx > n 处),节目亦提前终止。

你需要协助你的狗狗制定最优策略,使得在 TT 秒内吃到的狗粮碗数量最大化。

输入格式

Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped.

On the next line numbers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 109) are given, where t__i is the moment of time when the i-th bowl of food is ready for eating.

第一行给出两个整数 nn 和 TT(1 ≤ n ≤ 200 0001 ≤ n ≤ 200\,000,1 ≤ T ≤ 2⋅1091 ≤ T ≤ 2·10^9)——分别为食物碗的数量以及狗被停止进食的时刻。

下一行给出 t1, t2, ..., tnt_1,\,t_2,\,...,\,t_n(1 ≤ ti ≤ 1091 ≤ t_i ≤ 10^9),其中 tit_i 表示第 ii 碗食物可供食用的时刻。

输出格式

Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds.

输出一个整数——狗在 T 秒内最多能吃的碗数。

输入输出样例

  • 输入#1

    3 5
    1 5 3

    输出#1

    2
  • 输入#2

    1 2
    1

    输出#2

    1
  • 输入#3

    1 1
    1

    输出#3

    0

说明/提示

In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third).

在第一个例子中,狗应跳过第二个碗,从第一和第三个碗中进食。

输入解题思路,AI测评打分。不知道怎么写?

首页