B. The Queue
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard 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.

Examples
input
10 15 2
2
10 13
output
12
input
8 17 3
4
3 4 5 8
output
2
Note

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.

题目链接:http://codeforces.com/contest/767/problem/B

题意:接待员的工作时间,结束时间,处理每个人的时间分别为ts,tf,t。现在有n个人明天将到达窗口的时间x[1],x[2]...x[n],,问明天什么时候去排队等待的时间最少。如果和某一个人同时到达,排在这个人的后面。数据保证答案可以买到票。

思路:模拟题。排在i-1~i人之间。比较x[i-1],x[i]-1与处理完i-1人的时候的时间sign进行比较。

代码:

 #include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=1e5+,INF=0x3f3f3f3f,MOD=1e9+;
ll x[MAXN];
int main()
{
ll ts,tf,t;
scanf("%lld%lld%lld",&ts,&tf,&t);
int n;
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%lld",&x[i]);
x[]=,x[n+]=tf+;
ll sign=ts;
ll Min=tf,ans=-;
for(int i=; i<=n+; i++)
{
if(sign>tf-t) break;
if(x[i-]==x[i]) {sign+=t;continue;}
///x[i-1]~x[i]-1;
if(x[i-]>sign)
{
if(x[i-]-sign<Min)
Min=x[i-]-sign,ans=x[i-];
}
else if(x[i]-<sign)
{
if(sign-(x[i]-)<Min)
Min=sign-(x[i]-),ans=x[i]-;
}
else
{
cout<<sign<<endl;
return ;
}
sign+=t;
}
cout<<ans<<endl;
return ;
}

Codeforces 767B. The Queue 模拟题的更多相关文章

  1. CodeForces 767B The Queue

    模拟. 情况有点多,需要仔细.另外感觉题目的$tf$有点不太对......而且数据水了. $0$ $5$ $2$ $2$ $0$ $5$ 这组数据按照题意的话答案可以是$2$和$4$,但是好多错的答案 ...

  2. CodeForces - 344D Alternating Current (模拟题)

    id=46667" style="color:blue; text-decoration:none">CodeForces - 344D id=46667" ...

  3. Codeforces 691C. Exponential notation 模拟题

    C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

  4. CodeForces - 344B Simple Molecules (模拟题)

    CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...

  5. CodeForces - 344E Read Time (模拟题 + 二分法)

    E. Read Time time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. CodeForces 681C Heap Operations (模拟题,优先队列)

    题意:给定 n 个按顺序的命令,但是可能有的命令不全,让你补全所有的命令,并且要求让总数最少. 析:没什么好说的,直接用优先队列模拟就行,insert,直接放入就行了,removeMin,就得判断一下 ...

  7. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

随机推荐

  1. 环境变量之path的一点理解

    最初安装java环境时一直不明白为什么要配置环境变量,百度了一下还是理解不透彻. 后来安装python时也要配置环境变量.. 在经过未配置和配置的操作后,才有些理解path的含义. 1.未配置环境变量 ...

  2. 输入框状态禁止enter键提交表单

    1:页面中如果存在input输入框和submit提交按钮时,默认按enter键会提交表单,如果我现在在做查询操作,一不小心按了enter键就会有提交表单的操作,这样显然是不合理的,所以我们要禁止按en ...

  3. centos下send-mail出错

    当在脚本中执行发邮件操作得时候出现以下错误:send-mail: fatal: parameter inet_interfaces: no local interface found for ::1 ...

  4. mongo副本集设置主库权重,永远为主

    mongo副本集设置主库权重,即使主库宕机了再重启也还是主库. cfg = rs.conf()     ------->(查看序列)cfg.members[0].priority = 1 (设置 ...

  5. Java方法的重载和重写

    重载与重写对比:  重载: 权限修饰符(public private 默认):无关 方法名:重载的两个方法的方法名必须相同 形参的个数不同 形参的类型不同 三者至少满足一个 返回值类型: 重载与返回值 ...

  6. Calling Synchronous Methods Asynchronously

    [Calling Synchronous Methods Asynchronously] 使用 .NET Framework 可以以异步方式调用任何方法. 要实现此操作,请定义一个委托,此委托具有与你 ...

  7. ftp删除目录和文件,目录下有文件删除提示【550 Remove directory operation failed.】

      注意:目录下有文件,直接删除目录会失败,提示550 Remove directory operation failed. 必须先将目录下的文件都删除,才能删除目录   ftp命令行: ftp删除目 ...

  8. HibernateDaoSupport类的使用(转)

    看到一篇很好描述HibernateDaoSupport类使用的例子,特此在这和大家分享一下 核心提示:1. 继承了HibernateDaoSupport类的类获取session时,已不可用Sessio ...

  9. EM算法之GMM聚类

    以下为GMM聚类程序 import pandas as pd import matplotlib.pyplot as plt import numpy as np data=pd.read_csv(' ...

  10. Linux系统一本通(实用篇)

    本人最近一直在ubuntu,接下来和大家分享我曾经踩过的坑,和一些非常实用的命令知识- 安装中的磁盘分配 一般来说,在linux系统中都有最少两个挂载点,分别是/ (根目录)及 swap(交换分区), ...