国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Codeforces 767 B The Queue

2019-11-08 02:30:48
字體:
供稿:網(wǎng)友
B. The Queuetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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 ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf?-?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!

Input

The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf 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 ts?<?tf. 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.

Output

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.

Examplesinput
10 15 2210 13output
12input
8 17 343 4 5 8output
2Note

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.

題目大意:首先吐槽一下題目很長(zhǎng),,,意思很繁雜。就是一個(gè)人想去辦理事情,想等待最少的時(shí)間去辦理,現(xiàn)在他知道當(dāng)天辦公室的開門時(shí)間和工作人員對(duì)于每個(gè)人的接待時(shí)間和他們的工作時(shí)間,然后他還知道當(dāng)天去辦理業(yè)務(wù)的每個(gè)人的到達(dá)時(shí)間,如果他和其他人在同時(shí)到達(dá)那里的話,他需要排在最后去辦理,還有就是工作人員在剩余工作時(shí)間不足以完成一個(gè)人的業(yè)務(wù)辦理的時(shí)候,他不會(huì)給新來的人辦理業(yè)務(wù)。

題目分析:意思理解完了之后,就是有點(diǎn)模擬了,不過自我感覺這道題目特別考驗(yàn)思維的轉(zhuǎn)折,因?yàn)榻o你的數(shù)列是一個(gè)非遞減的數(shù)列,所以你只需要從頭開始遍歷就行了,然后對(duì)于每個(gè)人的到達(dá)時(shí)間,你選擇是否在他們前面一分鐘到達(dá)并且工作人員可以幫助下一位人處理完事情,并且你還需要更新最短的用時(shí),當(dāng)然不能忘記,這個(gè)最短的等待時(shí)間是有可能是0分鐘的。

#include <bits/stdc++.h>using namespace std;#define maxn 1e12+7long long m=maxn;long long k,a,n,ts,tf,t,ans;int main(){	cin>>ts>>tf>>t;	cin>>n;    while(n--){		cin>>k;		if(k<=tf-t){//判斷工作人員是否在剩余的時(shí)間完成業(yè)務(wù)辦理 			if(k && max(ts,k-1)<=tf-t && ts-k+1 < m ){//ts是不斷更新的工作人員可以開始辦理下一個(gè)業(yè)務(wù)的時(shí)間,			                                         //m是當(dāng)前需要等待的最短時(shí)間。 				m=ts-k+1;				ans=min(ts,k-1);       			}			ts=max(ts,k)+t;//不斷更新ts 		}	}	if(ts <= tf-t)  ans=ts;//判斷是否可以在最后不需要等待直接辦理 	cout<<ans<<endl;	return 0;}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 明星| 永安市| 芜湖市| 保德县| 土默特右旗| 永城市| 廉江市| 天长市| 南澳县| 全椒县| 唐河县| 广汉市| 潍坊市| 石狮市| 英德市| 石河子市| 大城县| 阿瓦提县| 崇仁县| 岳阳县| 泰安市| 文水县| 金阳县| 富民县| 西宁市| 花莲县| 思茅市| 金门县| 洱源县| 富源县| 阳泉市| 吴川市| 会泽县| 思茅市| 岗巴县| 遂溪县| 拜泉县| 全南县| 德庆县| 德阳市| 会同县|