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

set模板

#include
#include
#include
#include
#include
#include
#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 y2],tmp;
multiset

cs; multiset

::iterator it; bool cmp(P a,P b){return a.x1;} 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"); } }

你可能感兴趣的:(set)