CF887D.Ratings and Reality Shows

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are two main kinds of events in the life of top-model: fashion shows and photo shoots. Participating in any of these events affects the rating of appropriate top-model. After each photo shoot model's rating increases by aa and after each fashion show decreases by bb (designers do too many experiments nowadays). Moreover, sometimes top-models participates in talk shows. After participating in talk show model becomes more popular and increasing of her rating after photo shoots become cc and decreasing of her rating after fashion show becomes dd .

Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will never become negative. Help her to find a suitable moment for participating in the talk show.

Let's assume that model's career begins in moment 0. At that moment Izabella's rating was equal to startstart . If talk show happens in moment tt if will affect all events in model's life in interval of time [t..t+len)[t..t+len) (including tt and not including t+lent+len ), where lenlen is duration of influence.

Izabella wants to participate in a talk show, but she wants to do it in such a way that her rating will not become become negative before talk show or during period of influence of talk show. Help her to find a suitable moment for participating in the talk show.

输入格式

In first line there are 7 positive integers nn , aa , bb , cc , dd , startstart , lenlen ( 1<=n<=31051<=n<=3·10^{5} , 0<=start<=1090<=start<=10^{9} , 1<=a,b,c,d,len<=1091<=a,b,c,d,len<=10^{9} ), where nn is a number of fashion shows and photo shoots, aa , bb , cc and dd are rating changes described above, startstart is an initial rating of model and lenlen is a duration of influence of talk show.

In next nn lines descriptions of events are given. Each of those lines contains two integers tit_{i} and qiq_{i} ( 1<=ti<=1091<=t_{i}<=10^{9} , 0<=q<=10<=q<=1 ) — moment, in which event happens and type of this event. Type 0 corresponds to the fashion show and type 1 — to photo shoot.

Events are given in order of increasing tit_{i} , all tit_{i} are different.

输出格式

Print one non-negative integer tt — the moment of time in which talk show should happen to make Izabella's rating non-negative before talk show and during period of influence of talk show. If there are multiple answers print smallest of them. If there are no such moments, print 1-1 .

输入输出样例

  • 输入#1

    5 1 1 1 4 0 5
    1 1
    2 1
    3 1
    4 0
    5 0
    

    输出#1

    6
  • 输入#2

    1 1 2 1 2 1 2
    1 0
    

    输出#2

    -1
首页