题目链接:
http://hihocoder.com/problemset/problem/1391
题目大意:
A和B两个国家互射导弹,每个国家都有一个防御系统,在防御系统开启的时间内可以将到达本国的导弹反弹回去(掉头,防御系统不能开开关关)。
现在已知:Ta、Tb为A、B两国导弹防御能开启的持续时间,X为B国开启导弹防御系统的时刻(持续时间为[X,Tb+X],包含端点)
A向B发射N枚导弹,B向A发射M枚导弹。每枚导弹有3个值:发射时间,从A到B或从B到A的飞行时间,伤害值。
现在A可以在任意时刻开启防御系统,求A所受到的最小伤害值。
题目思路:
【预处理+排序+堆】
首先预处理,求出每枚导弹不会打到A需要A国防御系统开启的时间段[st,et],只有A开启防御的时间段[Y,Y+Ta]包含[st,et]那么这枚导弹不会打到A。
预处理之后将每枚导弹按照et从小到大排序。
从1到n+m枚导弹,对于当前这枚导弹,如果需要被防御,那么A防御系统的结束时间就为et,那么开启时间就为et-Ta
那么将之前已经被防御的导弹中st<et-Ta的移除出去,表示这些导弹不能在当前决策中被防御。
可以开个STL的优先队列或者堆记录之前被防御的导弹序号,按照st从小到大存,每次比较最小的st和开启时间et-Ta。并在过程中增减伤害值,并记录最小伤害。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 20004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int Ta,Tb,X,sum;
struct xxx
{
LL st,ct,et,d;
}a[N],b[N];
struct cmp1
{
bool operator ()(const int &aa,const int &bb)
{
return a[aa].st>a[bb].st;
}
};
bool cmp(xxx aa,xxx bb)
{
return aa.et<bb.et;
}
int main()
{
#ifndef ONLINE_JUDGEW
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
// while(~scanf("%d",&n))
while(~scanf("%d%d",&Ta,&Tb))
{
lll=;ans=MAX;sum=;
scanf("%d%d%d",&X,&n,&m);
for(i=;i<=n;i++)
{
scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
b[i].et=b[i].st+b[i].ct;
if(b[i].et>=X && b[i].et<=X+Tb)
{
sum+=b[i].d;
a[++lll].st=b[i].et+b[i].ct;
j=Tb+X-a[lll].st;
j=j%(*b[i].ct);
a[lll].et=Tb+X-j;
a[lll].d=b[i].d;
if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
}
}
for(i=;i<=m;i++)
{
scanf("%d%d%d",&b[i].st,&b[i].ct,&b[i].d);
b[i].et=b[i].st+b[i].ct;
sum+=b[i].d;
a[++lll].st=b[i].et;
j=Tb+X-a[lll].st;
j=j%(*b[i].ct);
a[lll].et=Tb+X-j;
a[lll].d=b[i].d;
if(j>=b[i].ct)a[lll].et+=b[i].ct+b[i].ct;
if(a[lll].st+b[i].ct<X || a[lll].st>Tb+X)a[lll].et=a[lll].st;
}
sort(a+,a+lll+,cmp);
priority_queue<int,vector<int>,cmp1>q; for(i=;i<=lll;i++)
{
q.push(i);y=a[i].et;
sum-=a[i].d;
x=q.top();
while(y-a[x].st>Ta && !q.empty())
{
sum+=a[x].d;
q.pop();x=q.top();
}
ans=min(ans,sum);
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/