CF887D.Ratings and Reality Shows

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 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.

顶级模特的职业生涯中主要有两类活动:时装秀和摄影拍摄。参与其中任意一类活动都会影响该顶级模特的评分。每次摄影拍摄后,模特的评分增加 aa;每次时装秀后,模特的评分减少 bb(如今设计师们进行了太多实验)。此外,有时顶级模特还会参加脱口秀。参加脱口秀后,模特会变得更加受欢迎,从而导致其后续摄影拍摄带来的评分增幅变为 cc,而后续时装秀导致的评分减幅变为 dd。

伊莎贝拉希望参加一次脱口秀,但她希望选择一个恰当的时机,使得她的评分在脱口秀开始前以及脱口秀影响力持续期间永远不会变为负数。请帮她找出一个合适的参加脱口秀的时刻。

我们假设模特的职业生涯始于时刻 00,此时伊莎贝拉的评分为 startstart。若脱口秀发生在时刻 tt,则其影响力将覆盖模特生命中时间区间 [t, t+len)[t,\, t + len) 内的所有事件(包含 tt,不包含 t+lent + len),其中 lenlen 表示该脱口秀影响力的持续时间。

伊莎贝拉希望参加一次脱口秀,但她要求:在脱口秀开始前,以及在脱口秀影响力持续期间,她的评分均不得变为负数。请帮她找出一个满足条件的参加脱口秀的合适时刻。

输入格式

In first line there are 7 positive integers n, a, b, c, d, start, len (1 ≤ n ≤ 3·105, 0 ≤ start ≤ 109, 1 ≤ a, b, c, d, len ≤ 109), 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 ≤ 109, 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.

第一行包含 7 个正整数 nn、aa、bb、cc、dd、startstart、lenlen(其中 1 ≤ n ≤ 3⋅1051 ≤ n ≤ 3·10^5,0 ≤ start ≤ 1090 ≤ start ≤ 10^9,1 ≤ a, b, c, d, len ≤ 1091 ≤ a,\,b,\,c,\,d,\,len ≤ 10^9),其中 nn 表示时装秀与摄影拍摄的总场次,aa、bb、cc 和 dd 是上述描述的评分变化量,startstart 是模特的初始评分,lenlen 是脱口秀影响持续的时间长度。

接下来 nn 行给出各事件的描述。每行包含两个整数 tit_i 和 qiq_i(1 ≤ ti ≤ 1091 ≤ t_i ≤ 10^9,0 ≤ qi ≤ 10 ≤ q_i ≤ 1),分别表示事件发生的时刻和事件类型。类型 00 对应时装秀,类型 11 对应摄影拍摄。

所有事件按 tit_i 严格递增顺序给出,且所有 tit_i 互不相同。

输出格式

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.

输出一个非负整数 tt —— 即脱口秀应举办的时刻,使得伊莎贝拉的评分在脱口秀开始前及脱口秀影响期间均非负。若存在多个解,输出其中最小的一个;若不存在满足条件的时刻,则输出 −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

输入解题思路,AI测评打分。不知道怎么写?

首页