444 D. Ratings and Reality Shows

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.

Input

In first line there are 7 positive integers nabcdstartlen (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, abc 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 ti and qi(1 ≤ ti ≤ 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 ti, all ti are different.

Output

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.

Examples
input
Copy
5 1 1 1 4 0 5
1 1
2 1
3 1
4 0
5 0
output
6
input
Copy
1 1 2 1 2 1 2
1 0
output
-1

 题意:

一个模特有两种活动。 
① 拍照片,挣钱 a。 ②开演唱会,花费b 
给定模特这两种工作的时间表。 
模特可以选定一个时间举办一个座谈会,那么他拍照片的钱变c。开演唱会会花费d。 
要求在模特座谈会之前和后len天(注意时间范围) 都不能赔钱。 要求你输出最小的座谈会天数。 没有输出-1.。 

 


思路:枚举第i天作为 开始的茶话会的时间(茶话会是可以和当天其他的活动撞的,并且当天有影响),然后计算后len天是否有负数。 

尺取+维护正常天数的前缀和

 

// 去吧!皮卡丘! 把AC带回来!
//      へ     /|
//   /\7    ∠_/
//   / │   / /
//  │ Z _,< /   /`ヽ
//  │     ヽ   /  〉
//  Y     `  /  /
//  イ● 、 ●  ⊂⊃〈  /
//  ()  へ    | \〈
//   >ー 、_  ィ  │ //
//   / へ   / ノ<| \\
//   ヽ_ノ  (_/  │//
//    7       |/
//    >―r ̄ ̄`ー―_
//**************************************
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <class T> inline T min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int maxn = 3e5 + 10;
const int maxx = 1e6 + 10;
// name*******************************
int n, a, b, c, d, s, len;
int t[maxn], q[maxn];
ll sum = 0, minn = INF;
ll rating = 0;
// function******************************

//***************************************
int main() {
  // ios::sync_with_stdio(0); cin.tie(0);
  // freopen("test.txt", "r", stdin);
  //  freopen("outout.txt","w",stdout);
  scanf1(n);
  scanf4(a, b, c, d);
  scanf2(s, len);
  For(i, 1, n) scanf2(t[i], q[i]);
  int pos = 1;
  t[0] = -1;
  rating = s;
  For(i, 1, n) {
    //这里是保证开座谈会后len时间内不赔钱
    while (pos <= n && t[pos] - t[i] < len) {
      sum += q[pos] ? c : -d;
      minn = min(minn, sum);//贪心:我们这里只要判断迭代后最小的那个对rating产生的影响就行
      pos++;
    }
    if (rating + minn >= 0) {
      cout << t[i - 1] + 1;
      return 0;
    }
    //下一次已经不用i了,所以减掉
    sum -= q[i] ? c : -d;
    minn -= q[i] ? c : -d;
    rating += q[i] ? a : -b;
    //这里在保证开座谈会前不赔钱
    if (rating < 0) {
      cout << -1;
      return 0;
    }
  }
  cout << t[n] + 1;

  return 0;
}

 

 

 

转载于:https://www.cnblogs.com/planche/p/8528128.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值