304649: CF887D. Ratings and Reality Shows

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Ratings and Reality Shows

题意翻译

### 题目描述 在顶级模特的生活中主要有两种活动:时装表演和照片拍摄。参加任何这些活动都会影响适当的顶级模特的评级。每次拍照后,模特的评分会增加 $a$,每次时装秀后会减少 $b$。此外,有时顶级模特会参加脱口秀。参加脱口秀后,模特变得更受欢迎,她在拍照后的评分增加为 $c$,在时装秀后的评分减少为 $d$。 伊莎贝拉想参加脱口秀,但她想以这样的方式使她的评分不会变成负值。请帮助她找到一个合适的时机来参加脱口秀。 让我们假设模特的职业生涯从 $0$ 时刻开始,在那一刻,伊莎贝拉的评分等于 $start$ 。如果脱口秀在 $t$ 时刻发生,那么将影响模特生活中的所有事件,时间间隔为 $[t \cdots t+len)$(包括 $t$ 和不包括 $t+len$),其中 $len$ 是影响的时间。 伊莎贝拉想参加一个脱口秀节目,但她希望在**脱口秀前或脱口秀影响期间**,她的评分不会变成负值。请帮助她找到一个合适的时机来参加谈话节目。 ### 输入格式: 第一行 $7$ 个整数,表示 $n,a,b,c,d,start,len$ 其中 $1 \le n \le 3 \times 10^5$,$0 \le start \le 10^9$,$1 \le a,b,c,d,len \le 10^9$。 接下来 $n$ 行整数,是 $t_i$ 和 $q_i$,如果 $q_i=1$ 那么就是拍照,否则就是时装表演。 $t_i$ 以递增给出,$t_i$ 互不相同。 ### 输出格式: 最小时间 $t$ 他开始脱口秀的时间。

题目描述

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 $ a $ and after each fashion show decreases by $ b $ (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 $ c $ and decreasing of her rating after fashion show becomes $ d $ . 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 $ start $ . If talk show happens in moment $ t $ if will affect all events in model's life in interval of time $ [t..t+len) $ (including $ t $ and not including $ t+len $ ), where $ len $ 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 $ n $ , $ a $ , $ b $ , $ c $ , $ d $ , $ start $ , $ len $ ( $ 1<=n<=3·10^{5} $ , $ 0<=start<=10^{9} $ , $ 1<=a,b,c,d,len<=10^{9} $ ), where $ n $ is a number of fashion shows and photo shoots, $ a $ , $ b $ , $ c $ and $ d $ are rating changes described above, $ start $ is an initial rating of model and $ len $ is a duration of influence of talk show. In next $ n $ lines descriptions of events are given. Each of those lines contains two integers $ t_{i} $ and $ q_{i} $ ( $ 1<=t_{i}<=10^{9} $ , $ 0<=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 $ t_{i} $ , all $ t_{i} $ are different.

输出格式


Print one non-negative integer $ t $ — 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

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

Input

题意翻译

### 题目描述 在顶级模特的生活中主要有两种活动:时装表演和照片拍摄。参加任何这些活动都会影响适当的顶级模特的评级。每次拍照后,模特的评分会增加 $a$,每次时装秀后会减少 $b$。此外,有时顶级模特会参加脱口秀。参加脱口秀后,模特变得更受欢迎,她在拍照后的评分增加为 $c$,在时装秀后的评分减少为 $d$。 伊莎贝拉想参加脱口秀,但她想以这样的方式使她的评分不会变成负值。请帮助她找到一个合适的时机来参加脱口秀。 让我们假设模特的职业生涯从 $0$ 时刻开始,在那一刻,伊莎贝拉的评分等于 $start$ 。如果脱口秀在 $t$ 时刻发生,那么将影响模特生活中的所有事件,时间间隔为 $[t \cdots t+len)$(包括 $t$ 和不包括 $t+len$),其中 $len$ 是影响的时间。 伊莎贝拉想参加一个脱口秀节目,但她希望在**脱口秀前或脱口秀影响期间**,她的评分不会变成负值。请帮助她找到一个合适的时机来参加谈话节目。 ### 输入格式: 第一行 $7$ 个整数,表示 $n,a,b,c,d,start,len$ 其中 $1 \le n \le 3 \times 10^5$,$0 \le start \le 10^9$,$1 \le a,b,c,d,len \le 10^9$。 接下来 $n$ 行整数,是 $t_i$ 和 $q_i$,如果 $q_i=1$ 那么就是拍照,否则就是时装表演。 $t_i$ 以递增给出,$t_i$ 互不相同。 ### 输出格式: 最小时间 $t$ 他开始脱口秀的时间。

加入题单

上一题 下一题 算法标签: