标签: 范围 - CheaSim Blog

[cf-767b]The Queue

The Queue

题意

题意有点复杂,懒得写了。

题解

贪心。

注意的点就是,可以在还没有开始就进入队列进行排队,所以计算的时候虽然是一样的,但还是要注意一下。

特殊情况就是对于在ed以后的人来说,他们就不算了,不算人。

+1 p数组 忘记开long long了。

+1 如果加入时间超过进入时间了就不行了。

ac代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define per(i,a,n) for(int i=(n-1);i>=(a);i--)
#define fi first
#define se second
typedef pair <int,int> pII;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//head
ll st,ed,t;
int n;
const int maxn = 1e5+10;
ll p[maxn];
int main(){
#ifdef LOCAL
freopen("4.in","r",stdin);
#endif
scanf("%lld%lld%lld",&st,&ed,&t);
scanf("%d",&n);
rep(i,0,n) scanf("%lld",p+i),p[i]-=st;
ed -= st;
ll ans = 1e13;
ll wait = 1e14;
int cnt = 0;
rep(i,0,n){
if( (ll)(i+1)*t>ed || p[i]+t>ed) break;
cnt++;
if(p[i] > (ll)(i)*t && p[i]+t<=ed){
ans = p[i]-1;
cout<<ans+st<<'\n';
return 0;
}else{
ll temp = (ll)(i)*t - p[i];
if(wait > temp){
wait = temp;
ans = p[i]-1ll;
}
}
}
ll temp = (ll)(cnt+1)*t; if(temp<=ed) ans = temp-t;
printf("%lld\n",ans+st);

return 0;
}