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;
}
posted @ 2016-09-25 14:16  basasuya  阅读(121)  评论(0编辑  收藏  举报