A. Cashier
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has recently got a job as a cashier at a local store. His day at work is LL minutes long. Vasya has already memorized nn regular customers, the ii-th of which comes after titi minutes after the beginning of the day, and his service consumes lili minutes. It is guaranteed that no customer will arrive while Vasya is servicing another customer.
Vasya is a bit lazy, so he likes taking smoke breaks for aa minutes each. Those breaks may go one after another, but Vasya must be present at work during all the time periods he must serve regular customers, otherwise one of them may alert his boss. What is the maximum number of breaks Vasya can take during the day?
Input
The first line contains three integers nn, LL and aa (0≤n≤1050≤n≤105, 1≤L≤1091≤L≤109, 1≤a≤L1≤a≤L).
The ii-th of the next nn lines contains two integers titi and lili (0≤ti≤L−10≤ti≤L−1, 1≤li≤L1≤li≤L). It is guaranteed that ti+li≤ti+1ti+li≤ti+1 and tn+ln≤Ltn+ln≤L.
Output
Output one integer — the maximum number of breaks.
Examples
input
Copy
2 11 3 0 1 1 1
output
3
input
0 5 2
output
2
input
1 3 2 1 2
output
0
Note
In the first sample Vasya can take 33 breaks starting after 22, 55 and 88 minutes after the beginning of the day.
In the second sample Vasya can take 22 breaks starting after 00 and 22 minutes after the beginning of the day.
In the third sample Vasya can't take any breaks.
题意:
给你n个任务,每一个任务给出开始时间和持续时间,给出总时间和抽烟花费的时间,求不影响任务的进行可以抽多少烟,抽烟不能间断。
分析:
暴力枚举即可,做一点小优化就行,开代码就懂
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
const int N = 100010;
ll t[N],l[N];
int main(){
ll n, L,a;
while (~scanf("%lld%lld%lld", &n, &L,&a) )
{
for(int i=1;i<=n;i++)
scanf("%lld%lld",&t[i],&l[i]);
ll ans=0;
ll i=0,j=1;
while(i<=L)
{
if(i>=L) break;
if(i+a>L) break;
if(i+a>t[j]&&j<=n)
{
i=t[j]+l[j];
j++;
}
else
{
ll temp;
if(j<=n)
temp=t[j]-i;
else
temp=L-i;
ll an=temp/a;
ans+=an; //小优化
i+=an*a;
}
}
printf("%lld\n",ans);
}
return 0;
}
标签:Vasya,ll,breaks,after,Cashier,Codeforces,include,minutes,Round From: https://blog.51cto.com/u_14932227/6042468