CodeForces 767B The Queue

题目链接:http://codeforces.com/contest/767/problem/B
题意:有一家卖票的机构,开始营业时间为ts,结束营业时间为tf,服务一个人的时间为t,现有n个人排队买票,告诉你每个人排队的时间,问你要尽可能快的买到票,该何时去插队。
解析:插队肯定是要么插在队头,要么就插在队尾,或者插在两个人之间,插在两个人之间,这样就有两种情况,就是比如a[i-1]处理完以后没人排队,那么肯定是现在出去插队是最好的,因为根本不用等,除此之外插在a[i]-1的情况是最好的,维护一下答案就行(注意用long long)

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <list>
using namespace std;
const int maxn = 2e5+100;
const int long long inf = 0x7ffffffffff;
long long a[maxn];

int main()
{
    long long ts,tf,t;
    scanf("%I64d %I64d %I64d",&ts,&tf,&t);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%I64d",&a[i]);
    long long minn = inf,ans = 0;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=tf-t)
        {
            if(a[i]>0)
            {
                int tmp = max(ts,a[i]-1);
                if(tmp<=tf-t && ts-a[i]+1<minn)
                {
                    minn = ts-a[i]+1;
                    //printf("%d:%I64d %I64d %I64d\n",i,ts,a[i],a[i]-1);
                    ans = min(ts,a[i]-1);
                }
            }
            ts = max(ts,a[i])+t;
        }
    }
    if(ts<=tf-t)
        ans = ts;
    printf("%I64d\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值