CF767B.The Queue

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.

He knows that the receptionist starts working after t__s minutes have passed after midnight and closes after t__f minutes have passed after midnight (so that (t__f - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves).

Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.

"Reception 1"

For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.

Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!

终于!瓦西娅成年了,这意味着他终于可以办理护照了!为此,他需要前往护照办公室,但这并不简单。护照办公室只有一名接待员,人们往往在办公室开门前很久就已排起长队。瓦西娅打算明天去护照办公室。

他了解到:接待员在午夜过后 tst_s 分钟开始工作,并在午夜过后 tft_f 分钟结束工作(即接待员仍在工作的最后一分钟是 tf−1t_f - 1)。接待员为队列中的每位访客恰好花费 tt 分钟。如果接待员将在 tt 分钟内停止工作,则他将不再为新访客提供服务(但若已开始为某位访客服务,则会完成该次服务)。

瓦西娅还知道:明天将恰好有 nn 位访客前来。对于每位访客,瓦西娅知道其到达护照办公室的具体时刻。每位访客都会排队等候,直至被接待完毕才离开。若某位访客到达时接待员恰好空闲(特别是前一位访客刚被服务完毕且队列为空),则接待员会立即开始为其服务。

"接待 1"

每位访客的到达时刻均为正整数。瓦西娅可在时刻零(即午夜)抵达办公室(如有需要),但他仅能在整数时刻抵达。若瓦西娅与其他若干访客在同一时刻抵达护照办公室,则他须礼让他人,排在他们所有人之后。

瓦西娅希望选择一个抵达时刻,使得自己能被接待员成功服务,且在队列中等待的时间尽可能短。请帮助他!

输入格式

The first line contains three integers: the point of time when the receptionist begins to work t__s, the point of time when the receptionist stops working t__f and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office.

All times are set in minutes and do not exceed 1012; it is guaranteed that t__s < t__f. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist.

第一行包含三个整数:接待员开始工作的时刻 tst_s、接待员结束工作的时刻 tft_f,以及接待员为每位访客服务所花费的时间 tt。
第二行包含一个整数 nn —— 访客的数量(0≤n≤100 0000 \leq n \leq 100\,000)。
第三行包含若干个按非递减顺序排列的正整数 —— 各访客抵达护照办公室的时刻。

所有时间均以分钟为单位,且不超过 101210^{12};保证 ts<tft_s < t_f。同时保证瓦夏可以恰好在某个时刻抵达护照办公室,从而被接待员接待。

输出格式

Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them.

输出一个非负整数——即瓦西娅应到达护照办公室的时刻。如果瓦西娅与若干其他访客在同一时刻到达护照办公室,则他礼让他人,排在队列末尾。若存在多个可行答案,输出任意一个即可。

输入输出样例

  • 输入#1

    10 15 2
    2
    10 13

    输出#1

    12
  • 输入#2

    8 17 3
    4
    3 4 5 8

    输出#2

    2

说明/提示

In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight.

In the second example, Vasya has to come before anyone else to be served.

在第一个例子中,第一位访客恰好在接待员开始工作的时间到达,并接受两分钟的服务。在午夜过后 12 分钟时,接待员结束对第一位访客的服务;若瓦夏在此刻到达,他将立即得到服务,因为下一位访客要到午夜过后 13 分钟才会到来。

在第二个例子中,瓦夏必须在其他任何人之前到达才能获得服务。

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

首页