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

首頁 > 學院 > 開發設計 > 正文

Codeforces Round #398(Div. 2)B. The Queue【貪心+謹慎】這題好尼瑪強勁

2019-11-08 02:25:33
字體:
來源:轉載
供稿:網友

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 aftertf minutes have passed after midnight (so that(tf?-?1) is the last minute when the receptionist is still working). The receptionist spends exactlyt minutes on each person in the queue. If the receptionist would stop working withint 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 workts, the point of time when the receptionist stops workingtf and the time the receptionist spends on each visitort. 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 thatts?<?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. 

題目大意:

一個工作窗口,從ts開放到tf.工作人員很負責,只要到時間一定上崗,到時間一定離開崗位。

處理每一個人的需求需要用k時間。 

現在已知這一天有N個人將要來辦理業務,來的時間已經給出。

現在主人公想要等待的時間最短,問什么時刻去最好。

思路:

1、問題的大方向很好考慮:

①要么主人公在所有人之前來,要么主人公在所有人之后來。

②再要么就是在每一個人之前一個單位時間來。

以上是所有可能的最優時間。

那么我們需要對其進行逐一判斷。

2、需要注意幾個點:

①這N個人來的時間都是此起彼伏的,有可能早來,當然,也有可能遲到。

②有可能一個人都沒有,就是N==0的情況。

③我萌一定要在結束工作之前,辦理業務。

④在最開始來的時候,時間不能為負。

.......................................................

細節很多的一個題,坑點很多...................

Ac代碼:

#include<stdio.h>#include<string.h>#include<algorithm>#include<map>using namespace std;#define ll __int64ll a[100060];int main(){    ll l,r,t;    while(~scanf("%I64d%I64d%I64d",&l,&r,&t))    {        map<ll,int >s;        int n;        scanf("%d",&n);        for(int i=1;i<=n;i++)        {            scanf("%I64d",&a[i]);            s[a[i]]=1;        }        sort(a+1,a+1+n);        ll wait=0x3f3f3f3f;        ll output=0x3f3f3f3f;        ll now;        ll preend;        if(a[1]-1>=0)output=a[1]-1,wait=abs(output-l);//所有人之前來        if(l<a[1])output=l,wait=0;        for(int i=1;i<=n;i++)        {            ll tmpoutput=output;            if(i==1)            {                if(a[i]<l)now=l;                else now=a[i];                preend=now+t;            }            else            {                if(preend<a[i])                {                    output=preend;                    wait=0;                }                else                {                    if(preend-(a[i]-1)<wait)                    {                        wait=preend-(a[i]-1);                        output=a[i]-1;                    }                    now=preend;                    preend=now+t;                }            }            if(output+t>=r)output=tmpoutput;        }        if(preend+t<=r)output=preend;//所有人之后來        if(n==0)output=l;        printf("%I64d/n",output);    }}


上一篇:No525ContiguousArray

下一篇:讀書摘要

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鲁甸县| 武汉市| 遵义县| 上虞市| 丹巴县| 新密市| 沙洋县| 苍溪县| 墨江| 会东县| 延寿县| 拉孜县| 太仆寺旗| 客服| 柘荣县| 甘孜| 吉木乃县| 阳谷县| 友谊县| 太谷县| 宁陕县| 巩义市| 拉孜县| 鸡泽县| 宜宾市| 平遥县| 海门市| 永仁县| 增城市| 郓城县| 梁河县| 靖远县| 绥棱县| 长丰县| 高邮市| 景洪市| 乌拉特中旗| 天峻县| 将乐县| 七台河市| 彭州市|