CF505E.Mr. Kitayuta vs. Bamboos

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mr. Kitayuta's garden is planted with nn bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the ii -th bamboo is hih_{i} meters, and it grows aia_{i} meters at the end of each day.

Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed because their stems are too hard. Mr. Kitayuta have not given up, however. He has crafted Magical Hammer with his intelligence to drive them into the ground.

He can use Magical Hammer at most kk times during each day, due to his limited Magic Power. Each time he beat a bamboo with Magical Hammer, its height decreases by pp meters. If the height would become negative by this change, it will become 00 meters instead (it does not disappear). In other words, if a bamboo whose height is hh meters is beaten with Magical Hammer, its new height will be max(0,hp)max(0,h-p) meters. It is possible to beat the same bamboo more than once in a day.

Mr. Kitayuta will fight the bamboos for mm days, starting today. His purpose is to minimize the height of the tallest bamboo after mm days (that is, mm iterations of "Mr. Kitayuta beats the bamboos and then they grow"). Find the lowest possible height of the tallest bamboo after mm days.

输入格式

The first line of the input contains four space-separated integers nn , mm , kk and pp ( 1<=n<=105,1<=m<=5000,1<=k<=10,1<=p<=1091<=n<=10^{5},1<=m<=5000,1<=k<=10,1<=p<=10^{9} ). They represent the number of the bamboos in Mr. Kitayuta's garden, the duration of Mr. Kitayuta's fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during each day, and the power of Magic Hammer, respectively.

The following nn lines describe the properties of the bamboos. The ii -th of them ( 1<=i<=n1<=i<=n ) contains two space-separated integers hih_{i} and aia_{i} ( 0<=hi<=109,1<=ai<=1090<=h_{i}<=10^{9},1<=a_{i}<=10^{9} ), denoting the initial height and the growth rate of the ii -th bamboo, respectively.

输出格式

Print the lowest possible height of the tallest bamboo after mm days.

输入输出样例

  • 输入#1

    3 1 2 5
    10 10
    10 10
    15 2
    

    输出#1

    17
    
  • 输入#2

    2 10 10 1000000000
    0 10
    0 10
    

    输出#2

    10
    
  • 输入#3

    5 3 3 10
    9 5
    9 2
    4 7
    9 10
    3 8
    

    输出#3

    14
    
首页