【NOIP2017提高A组模拟8.22】时间机器

set模板

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define ll long long
using namespace std;
const ll inf=0x7fffffffffffffff;
int read(){
    int x=0;
    char ch=getchar();
    while (ch<'0' || ch>'9') ch=getchar();
    while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
    return x;
}
const int maxn=50005;

int i,j,k,l,n,x,y,z,t,m;
bool bz;
struct P{
    int x,y,z,w;
    bool operator <(const P &b)const{return y<b.y;}
}a[maxn*2],tmp;
multiset<P> cs;
multiset<P>::iterator it;
bool cmp(P a,P b){return a.x<b.x || a.x==b.x && a.w==1;}

int main(){
//  freopen("t2.in","r",stdin);
    freopen("machine.in","r",stdin);
    freopen("machine.out","w",stdout);
    t=read();
    while (t){
        t--;
        n=read(); m=read();
        l=0;
        fo(i,1,n+m){
            if (i==n+1) l=1;
            a[i].x=read(); a[i].y=read(); a[i].z=read(); a[i].w=l; 
        }
        sort(a+1,a+n+m+1,cmp);
        bz=false;
        cs.clear();
        fo(i,1,n+m)
        if (a[i].w==0){
            while (a[i].z){
                it=cs.lower_bound(a[i]);
                if (it!=cs.end()){
                    tmp=*it;
                    cs.erase(it);
                    x=min(a[i].z,tmp.z);
                    a[i].z-=x;
                    tmp.z-=x;
                    if (tmp.z) cs.insert(tmp);
                } else{
                    bz=true;
                    break;
                }
            }
            if (bz==true) break;
        } else cs.insert(a[i]);
        if (bz) printf("No\n"); else printf("Yes\n");
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值