hihocoder1391 Country

题解的那种前缀和以前没学过,感觉是种套路

#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e4+5;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

int Ta,Tb,X;
int N,M;
struct Node{
    int st,ti,da; 
    void inpu() {
        scanf("%d %d %d",&st,&ti,&da);
    }
}A[MAXN],B[MAXN*2];
map<int,int> mp;
map<int,int>::iterator it;


int main(){
    while(~scanf("%d %d %d",&Ta,&Tb,&X)) {
        mp.clear();
        scanf("%d %d",&N,&M);
        int tot = 0; int ans; 
        for(int i = 1; i <= N; ++i) A[i].inpu();
        for(int i = 1; i <= M; ++i) B[i].inpu(); 


        int st = X; int ed = X+Tb;
        for(int i = 1; i <= N; ++i) {
            if(A[i].st+A[i].ti >= st && A[i].st+A[i].ti <= ed) {
                B[++M].st = A[i].st+A[i].ti; B[M].ti = A[i].ti; B[M].da = A[i].da;
            }   
        }

        for(int i = 1; i <= M; ++i) {
            tot += B[i].da; int k = 0;
            if(B[i].st+2*B[i].ti >= st && B[i].st+2*B[i].ti <= ed) {
                k = (ed-B[i].st-2*B[i].ti)/2/B[i].ti + 1;
            }

            int t1 = B[i].st+B[i].ti; int t2 = t1+2*k*B[i].ti;
            if(t2-Ta < t1+1) {
                mp[t2-Ta] -= B[i].da; mp[t1+1] += B[i].da;
            }
        }

        ans = tot;
        for(it = mp.begin(); it != mp.end(); ++it) {
            tot += it->second;
            ans = min(ans,tot);
        }
        printf("%d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值