码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 912C Perun, Ult!

时间:2019-04-01 00:57:58      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:make   star   mes   pos   run   col   signed   class   clu   

Perun, Ult!

恶心题, 好多细节。。。 啊, 好恶心啊。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-9;
const double PI = acos(-1);

int n, m;
vector<PLL> vc[N];
vector<LL> prefix[N];
vector<LL> gg;
LL bou, inc, dam;
LL maxh[N], starth[N], regen[N];
vector<LL> oo;
vector<LL> cnt;
vector<PLL> add;

int getPos(LL x) {
    return lower_bound(oo.begin(), oo.end(), x) - oo.begin();
}

int main() {
    scanf("%d%d", &n, &m);
    scanf("%lld%lld%lld", &bou, &inc, &dam);
    for(int i = 1; i <= n; i++) {
        scanf("%lld%lld%lld", &maxh[i], &starth[i], &regen[i]);
        vc[i].push_back(mk(0, starth[i]));
    }
    for(int i = 1; i <= m; i++) {
        LL x, y, z; scanf("%lld%lld%lld", &x, &y, &z);
        vc[y].push_back(mk(x, z));
    }
    for(int i = 1; i <= n; i++) {
        if(maxh[i] <= dam && inc) {
            puts("-1");
            return 0;
        }
    }
    for(int i = 1; i <= n; i++) sort(vc[i].begin(), vc[i].end());
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < SZ(vc[i]); j++) {
            LL up = j < SZ(vc[i]) - 1 ? vc[i][j + 1].fi - 1 : INF;
            if(vc[i][j].se > dam) continue;
            if(regen[i]) {
                LL ret = (dam - vc[i][j].se) / regen[i];
                add.push_back(mk(vc[i][j].fi, min(up, vc[i][j].fi + ret)));
                oo.push_back(vc[i][j].fi);
                oo.push_back(min(up, vc[i][j].fi + ret) + 1);
            } else {
                if(up == INF && inc) {
                    puts("-1");
                    return 0;
                } else {
                    add.push_back(mk(vc[i][j].fi, up));
                    oo.push_back(vc[i][j].fi);
                    oo.push_back(up + 1);
                }
            }
        }
    }
    LL ans = 0;
    sort(oo.begin(), oo.end());
    oo.erase(unique(oo.begin(), oo.end()), oo.end());
    cnt.resize(SZ(oo));
    for(auto& t : add) {
        cnt[getPos(t.fi)]++;
        cnt[getPos(t.se + 1)]--;
    }
    for(int i = 0; i < SZ(cnt); i++) {
        if(i) cnt[i] += cnt[i - 1];
        ans = max(ans, 1LL * cnt[i] * (bou + (oo[i + 1] - 1) * inc));
    }
    printf("%lld\n", ans);
    return 0;
}

/*
*/

 

Codeforces 912C Perun, Ult!

标签:make   star   mes   pos   run   col   signed   class   clu   

原文地址:https://www.cnblogs.com/CJLHY/p/10634169.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!