zoukankan      html  css  js  c++  java
  • 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("***********
    ");
    #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;
    }
  • 相关阅读:
    人工智能学习笔记003-Python运算符
    人工智能学习笔记002-Python数据类型
    人工智能学习笔记001—python介绍
    dataclasses 笔记
    Js逆向-滑动验证码图片还原
    python3 marshmallow学习
    python 安装 SQLAlchemy 报错
    flask 与 SQLAlchemy的使用
    flask 与 flask_migrate的使用
    flask与flask-script的使用
  • 原文地址:https://www.cnblogs.com/planche/p/8528128.html
Copyright © 2011-2022 走看看