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
#include
#include
#include
#include
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;
}

你可能感兴趣的:(算法)