Gym - 102058M :Coke Challenge(模拟)

https://vjudge.net/problem/Gym-102058M

Mr. Jeong really loves coke. He loves so much that he drinks coke everyday without exception. One day, he decided to open a coke contest in Daejeon. To the winner, a box of cokes will be given!

N people participate in the contest. Each participant is given K mL of coke, and the one who finishes his/her coke earliest wins the contest. But it is painful to drink the whole coke in one time, so each person repeats drinking and taking a rest. More specifically, as soon as the contest starts, the ith participant starts to drink for ti seconds, then takes a rest for si seconds, and repeats this process until no more coke remains. Moreover, everyone drinks A mL per second. The contest is over if one of the participants finished his/her coke.

Given the infomation of N participants, determine after how many seconds the contest is finished, since the contest begins.

Input

The input starts with the first line containing three integers N (2 ≤ N ≤ 1000), K (1 ≤ K ≤ 10000), and A (1 ≤ A ≤ 100). The ith of the next N lines contains two integers ti (1 ≤ ti ≤ 100) and si (1 ≤ si ≤ 100), the information of ith participant. K is a multiple of A.

Output

Write a single integer, the answer to the question.

Examples

Input

2 100 1
10 5
5 10

Output

145

Input

4 100 2
30 30
49 2
50 50
20 10

Output

50

题意分析:

有一个喝汽水比赛,每个人喝 t 秒后必须休息 s 秒, 一共K毫升汽水,每秒可以喝 a 毫升,一旦有一个人喝完汽水,比赛结束,求比赛结束的时间。

解题思路:

对每个人喝完时间进行比较,找出最短的那一个, 如果一个人喝完汽水,那后面的等待时间就不用有。

第一次 sum=(s+t)*(k/t);  后面的 k/t 没加括号错了1次。

#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int n, k, a, ans, sum, t, s; 
	while(scanf("%d%d%d", &n ,&k, &a)!=EOF)
	{
		ans=99999999;
		k/=a;
		while(n--)
		{
			scanf("%d%d", &t, &s);
			sum=(s+t)*(k/t);
			if(k%t==0)
				sum-=s;
			else
				sum+=k%t;
			ans=min(ans, sum);
		}
		printf("%d\n", ans);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值