A. Cashier

A. Cashier

Vasya has recently got a job as a cashier at a local store. His day at work is L minutes long. Vasya has already memorized n regular customers, the i-th of which comes after ti minutes after the beginning of the day, and his service consumes li 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 a 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 n, L and a (0≤n≤105, 1≤L≤109, 1≤a≤L).

The i-th of the next n lines contains two integers ti and li (0≤ti≤L−1, 1≤li≤L). It is guaranteed that ti+li≤ti+1 and tn+ln≤L.

Output
Output one integer — the maximum number of breaks.

#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int Comp(const void*a, const void*b)
{
	return  *(int*)a - *(int*)b;
}
int max(int a, int b)
{
	if (a > b)
	{
		return a;
	}
	return b;
}
int main()
{
	int n, l, a;
	int tend = 0;
	int start, stay;
	int time = 0;
	int count = 0;
	cin >> n >> l >> a;
	while (n--)
	{
		cin >> start >> stay;
		time = start - tend;
		if (time >= a && time != 0)
		{
			count += time / a;
		}
		tend = start + stay;
	}
	time = l - tend;
	if (time >= a && time != 0)
	{
		count += time / a;
	}
	cout << count;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值