QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425126#8106. Mosaicjinqihao2023TL 3ms7168kbC++145.1kb2024-05-29 22:25:012024-05-29 22:25:01

Judging History

你现在查看的是最新测评结果

  • [2024-05-29 22:25:01]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:7168kb
  • [2024-05-29 22:25:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,x[N],y[N],b[N],T,cx[N],cy[N];
int mxup;
set<int>sx[N],sy[N];
map<pair<int,int>,int>mp;
int fx(int x){int pos=lower_bound(cx+1,cx+cx[0]+1,x)-cx;if(pos==cx[0]+1 || cx[pos]!=x)return -1;return pos;}
int fy(int y){int pos=lower_bound(cy+1,cy+cy[0]+1,y)-cy;if(pos==cy[0]+1 || cy[pos]!=y)return -1;return pos;}
struct Seg_tree
{
	struct STree{int lc,rc,add,minn;pair<int,int>maxn;}t[N*60];
	int tot,rt;
	void pushup(int p)
	{
		t[p].maxn=max(t[t[p].lc].maxn,t[t[p].rc].maxn);
		t[p].minn=min(t[t[p].lc].minn,t[t[p].rc].minn);
	}
	void update(int &p,int v,int l,int r)
	{
		if(!p)tot++,p=tot,t[p].lc=t[p].rc=0,t[p].maxn={mxup,-l},t[p].minn=mxup,t[p].add=0;
		t[p].maxn.first+=v,t[p].minn+=v,t[p].add+=v;
	}
	void pushdown(int p,int l,int r)
	{
		int mid=l+r>>1;
		update(t[p].lc,t[p].add,l,mid),update(t[p].rc,t[p].add,mid+1,r),t[p].add=0;
	}
	void change(int &p,int l,int r,int al,int ar,int v)
	{
		if(!p)p=++tot,t[p].lc=t[p].rc=0,t[p].maxn={mxup,-l},t[p].minn=mxup,t[p].add=0;
		if(al<=l && r<=ar)return update(p,v,l,r),void();
		pushdown(p,l,r);
		int mid=l+r>>1;
		if(al<=mid)change(t[p].lc,l,mid,al,ar,v);
		if(mid<ar)change(t[p].rc,mid+1,r,al,ar,v);
		pushup(p);
		// cout<<p<<" "<<l<<" "<<r<<" "<<t[p].minn<<" "<<mxup<<" "<<v<<endl;
	}
	int ask(int p,int l,int r,int al,int ar)
	{
		if(!p)return mxup;
		if(al<=l && r<=ar)return t[p].minn;
		pushdown(p,l,r);
		int mid=l+r>>1,res=mxup;
		if(al<=mid)res=min(res,ask(t[p].lc,l,mid,al,ar));
		if(mid<ar)res=min(res,ask(t[p].rc,mid+1,r,al,ar));
		return res;
	}
}t1;
int ans[N];
bool slv()
{
	// cout<<"mxup"<<mxup<<endl;
	t1.t[0].maxn={mxup,0},t1.t[0].minn=mxup,t1.tot=0,t1.rt=0;
	// cout<<(*sx[1].rbegin())<<endl;
	if(!sx[1].size())
	{
		while(1);
	}
	int nx=mxup-*sx[1].rbegin();
	vector<pair<int,int> >temp;
	ans[mp[{0,*sx[1].rbegin()}]]=nx;
	temp.push_back({0,nx-1});
	sx[1].erase(--sx[1].end());
	// cout<<(*sx[1].rbegin())<<endl;
	// cout<<nx<<" "<<fx(nx)<<endl;
	int cnt=1;
	while(fx(nx)!=-1)
	{
		int nx1=fx(nx);
		if(!sx[nx1].size())
		{
			while(1);
		}
		int ny=*sx[nx1].rbegin(),pos=mp[{nx,ny}];
		sx[nx1].erase(--sx[nx1].end());
		// cout<<nx<<" "<<ny<<" "<<pos<<endl;
		cnt++;
		ans[pos]=mxup-ny;
		temp.push_back({nx,nx+ans[pos]-1});
		nx+=ans[pos];
	}
	for(int i=1;i<=n;i++)if(cx[x[i]]>nx)return 0;
	// cout<<"nx"<<nx<<endl;
	int mxri=nx;
	// for(int i=0;i<mxri;i++)printf("%d ",t1.ask(t1.rt,0,mxri-1,i,i));printf("\n");
	// cout<<t1.t[0].lc<<" !!!!!!!!!!! "<<t1.t[0].rc<<endl;
	for(auto i:temp)t1.change(t1.rt,0,mxri-1,i.first,i.second,i.first-i.second-1);
	// for(int i=0;i<mxri;i++)printf("%d ",t1.ask(t1.rt,0,mxri-1,i,i));printf("\n");
	while(t1.t[t1.rt].maxn.first>0)
	{
		int x=-t1.t[t1.rt].maxn.second,y=t1.t[t1.rt].maxn.first,nx=fx(x);
		// cout<<x<<" "<<y<<" "<<nx<<" "<<sx[nx].size()<<endl;
		if(nx==-1 || !sx[nx].size())return 0;
		int ny=*sx[nx].rbegin();sx[nx].erase(--sx[nx].end());
		// cout<<ny<<endl;
		if(ny>=y)return 0;
		ans[mp[{x,ny}]]=y-ny;
		// cout<<y-ny<<endl;
		if(x+(y-ny)>mxri)return 0;
		if(t1.ask(t1.rt,0,mxri-1,x,x+(y-ny)-1)<y)return 0;
		t1.change(t1.rt,0,mxri-1,x,x+(y-ny)-1,ny-y);
		cnt++;
		// for(int i=0;i<mxri;i++)printf("%d ",t1.ask(t1.rt,0,mxri-1,i,i));printf("\n");
	}
	// cout<<cnt<<endl;
	if(cnt<n)return 0;
	return 1;
}
bool isans;
void solve1()
{
	// for(int i=1;i<=n;i++)printf("%d %d\n",x[i],y[i]);
	for(int i=1;i<=n;i++)mp[{x[i],y[i]}]=i;
	cx[0]=0,cy[0]=0;
	for(int i=1;i<=n;i++)cx[0]++,cx[cx[0]]=x[i],cy[0]++,cy[cy[0]]=y[i];
	sort(cx+1,cx+cx[0]+1),cx[0]=unique(cx+1,cx+cx[0]+1)-cx-1;
	sort(cy+1,cy+cy[0]+1),cy[0]=unique(cy+1,cy+cy[0]+1)-cy-1;
	for(int i=1;i<=n;i++)x[i]=lower_bound(cx+1,cx+cx[0]+1,x[i])-cx,y[i]=lower_bound(cy+1,cy+cy[0]+1,y[i])-cy;
	pair<int,int>mxx={-1,0};
	for(int i=1;i<=n;i++)if(x[i]==1)mxx=max(mxx,{y[i],i});
	for(int i=1;i<=cx[0];i++)if(cx[i])
	{
		mxup=cy[mxx.first]+cx[i];
		for(int j=1;j<=cx[0];j++)sx[j].clear();
		for(int j=1;j<=n;j++)sx[x[j]].insert(cy[y[j]]),ans[j]=0;
		if(slv())
		{
			isans=1;
			return ;
		}
	}
}
int xx[N],yy[N];
int ct,fir=-1;
void solve()
{
	scanf("%d",&n),isans=0;
	for(int i=1;i<=n;i++)scanf("%d %d",&x[i],&y[i]);
	ct++;
	if(fir==-1)fir=n;
	// if(ct==24 && fir==2)
	// {
	// 	printf("J%d\n",y[5]);
	// 	return ;
	// }
	if(n==1){printf("YES 1\n");return ;}
	int mnx=2e9,mny=2e9;
	for(int i=1;i<=n;i++)mnx=min(mnx,x[i]),mny=min(mny,y[i]);
	bool fl=0;
	for(int i=1;i<=n;i++)if(x[i]==mnx && y[i]==mny)fl=1;
	if(!fl){printf("NO\n");return ;}
	for(int i=1;i<=n;i++)x[i]-=mnx,y[i]-=mny,xx[i]=x[i],yy[i]=y[i];
	mp.clear();
	solve1();
	if(isans)
	{
		printf("YES ");
		for(int i=1;i<=n;i++)printf("%d ",ans[i]);
		printf("\n");
		return ;
	}
	mp.clear();
	for(int i=1;i<=n;i++)x[i]=yy[i],y[i]=xx[i];
	solve1();
	if(isans)
	{
		printf("YES ");
		for(int i=1;i<=n;i++)printf("%d ",ans[i]);
		printf("\n");
		return ;
	}
	printf("NO\n");
}
int main()
{
	// freopen("ex_puzzle2.in","r",stdin);
	// freopen("puzzle.out","w",stdout);
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6832kb

input:

3
2
0 0
0 1
2
3 2
2 3
4
1 1
2 1
3 1
1 2

output:

YES 1 1 
NO
YES 1 1 3 2 

result:

ok 3 testow OK.

Test #2:

score: 0
Accepted
time: 0ms
memory: 6948kb

input:

50
21
2 1
0 4
1 3
1 2
0 2
0 1
1 4
2 3
0 3
2 4
0 0
1 1
1 0
0 6
1 5
2 0
2 2
2 5
1 6
2 6
0 5
1
3 17
9
3 17
28 12
27 3
17 3
17 13
27 12
21 13
3 3
21 20
9
68 38
75 22
34 47
70 50
70 45
59 38
34 22
68 45
59 22
10
47 38
75 35
70 54
64 49
64 38
72 13
72 35
47 55
47 13
70 49
10
54 47
42 111
9 92
42 123
35 11...

output:

YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
YES 1
YES 18 8 9 10 4 1 7 14 15 
YES 7 28 36 33 5 9 25 2 16 
YES 17 19 24 6 11 22 3 23 25 5 
YES 60 12 26 28 7 33 45 19 16 44 
YES 15 26 41 4 7 57 11 3 44 54 
YES 34 4 16 55 15 11 60 19 39 23 
YES 35 12 34 41 23 3 44 11 45 38 
YES 2 15 25 30 11 3 8 27 1...

result:

ok 50 testow OK.

Test #3:

score: 0
Accepted
time: 0ms
memory: 6900kb

input:

50
2
2 1
3 1
3
1 2
1 3
1 1
4
0 0
0 1
0 2
0 3
5
1 6
1 7
1 4
1 8
1 5
5
2 5
4 5
5 2
3 5
2 2
4
6 5
5 3
5 5
7 3
5
2 5
2 3
2 4
3 3
3 4
5
1 0
3 0
0 2
0 0
0 1
5
11 2
8 1
5 1
11 3
11 1
4
4 3
2 2
4 2
0 2
5
3 1
1 1
0 1
0 2
3 2
5
1 5
8 5
8 6
6 5
6 7
5
2 3
2 2
3 2
4 2
2 6
3
2 2
1 3
1 2
4
3 3
2 3
3 2
2 2
5
5 0
4 ...

output:

YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 1 1 4 1 3 
YES 1 2 1 3 
YES 2 1 1 1 1 
YES 2 5 3 1 1 
YES 1 3 3 1 1 
YES 1 2 1 2 
YES 1 2 1 1 1 
YES 5 1 1 2 3 
YES 3 1 1 1 3 
YES 2 1 1 
YES 1 1 1 1 
YES 1 1 1 1 2 
YES 1 1 1 3 
YES 1 1 4 3 1 
YES 1 2 1 2 
YES 1 2 1 1 1 
YES 2 2 
YES 1 1 2 2 
YES ...

result:

ok 50 testow OK.

Test #4:

score: 0
Accepted
time: 2ms
memory: 6872kb

input:

50
5
3 7
5 7
7 7
3 4
6 4
3
6 1
6 4
9 1
5
6 2
6 0
3 3
6 1
3 0
5
2 0
2 1
5 0
2 2
3 0
5
2 5
2 2
5 4
5 2
5 6
5
8 7
2 4
7 8
7 7
7 4
4
6 6
9 9
6 9
9 6
2
2 7
2 11
5
4 1
5 0
6 0
7 0
4 0
3
3 7
5 5
3 5
4
16 5
18 3
16 3
10 3
5
1 7
5 3
5 6
3 7
1 3
5
11 9
6 5
9 9
6 8
9 5
3
8 2
4 2
4 6
4
6 6
6 10
10 8
10 6
4
3 2
...

output:

YES 2 2 2 3 3 
YES 3 3 6 
YES 1 1 4 1 3 
YES 1 1 5 3 2 
YES 3 3 2 2 2 
YES 2 5 1 1 3 
YES 3 3 3 3 
YES 4 4 
YES 3 1 1 4 1 
YES 2 4 2 
YES 4 2 2 6 
YES 2 3 3 2 4 
YES 2 3 2 3 4 
YES 8 4 4 
YES 4 6 2 2 
YES 4 4 4 4 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 2 2 
YES 2 1 1 
YES 1 2 2 1 
YES 1...

result:

ok 50 testow OK.

Test #5:

score: 0
Accepted
time: 2ms
memory: 6872kb

input:

50
4
1 1
3 1
5 1
5 2
5
3 3
2 6
3 6
2 3
2 4
2
3 2
1 2
4
8 1
9 0
6 0
8 0
5
1 4
2 4
1 6
1 5
2 5
5
8 8
7 8
4 8
7 9
4 3
3
2 4
1 4
1 2
4
4 1
8 1
7 2
7 1
3
9 2
7 4
7 2
4
2 0
5 2
6 2
5 0
5
8 2
8 5
8 4
3 2
9 4
4
4 2
4 0
6 2
6 0
5
13 4
13 2
7 2
11 4
11 2
5
5 4
5 7
3 4
3 6
3 8
4
3 2
3 8
5 8
7 8
5
7 2
6 3
6 5
6...

output:

YES 2 2 1 1 
YES 1 1 1 1 2 
YES 2 2 
YES 1 2 2 1 
YES 1 1 2 1 1 
YES 1 1 3 2 5 
YES 1 1 2 
YES 3 1 2 1 
YES 4 2 2 
YES 3 1 1 2 
YES 2 2 1 5 1 
YES 2 2 2 2 
YES 2 2 4 2 2 
YES 3 3 2 2 2 
YES 6 2 2 2 
YES 1 2 2 1 5 
YES 2 4 2 3 3 
YES 3 3 
YES 1 1 3 1 
YES 4 3 1 1 1 
YES 2 3 2 3 2 
YES 3 6 3 
YES 4 1 ...

result:

ok 50 testow OK.

Test #6:

score: 0
Accepted
time: 2ms
memory: 6836kb

input:

50
3
6 0
5 0
5 1
4
4 1
5 1
5 0
4 0
5
2 2
1 2
3 2
2 3
1 3
4
3 4
2 5
2 4
4 4
5
4 4
4 1
5 1
4 2
4 3
4
4 5
4 6
7 5
5 5
5
0 3
1 3
0 4
3 3
3 4
2
3 0
1 0
3
2 5
2 7
3 7
4
4 8
6 9
6 8
4 5
3
4 0
6 0
4 2
4
6 4
6 2
3 2
7 4
5
5 10
7 11
5 5
7 10
8 10
4
3 4
5 4
3 2
5 2
5
5 2
7 2
5 4
1 2
7 4
5
7 8
7 6
9 4
7 4
9 7
4...

output:

YES 2 1 1 
YES 1 1 1 1 
YES 1 1 2 1 1 
YES 1 2 1 3 
YES 1 1 4 1 1 
YES 1 1 2 2 
YES 1 2 1 1 1 
YES 2 2 
YES 2 1 1 
YES 2 1 1 3 
YES 2 4 2 
YES 1 2 3 1 
YES 2 1 5 1 2 
YES 2 2 2 2 
YES 2 2 2 4 2 
YES 2 2 3 2 3 
YES 2 2 2 6 
YES 2 1 5 2 1 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 2 2 
YES 1...

result:

ok 50 testow OK.

Test #7:

score: 0
Accepted
time: 0ms
memory: 6868kb

input:

50
5
5 4
3 3
6 4
5 3
6 3
3
5 5
3 5
1 5
4
5 0
4 1
7 0
4 0
2
6 3
9 3
4
3 4
4 3
3 5
3 3
2
4 10
4 6
2
0 6
1 6
3
3 0
4 0
5 0
4
7 4
4 4
6 4
5 4
5
5 4
5 5
5 6
5 8
5 7
2
3 2
5 2
3
6 5
8 5
10 5
2
3 5
6 5
2
4 2
4 6
2
2 3
2 2
3
1 0
3 0
2 0
4
2 5
2 6
2 7
2 4
5
1 4
1 6
1 7
1 5
1 3
5
6 5
4 5
5 5
4 2
7 2
4
4 2
4 4...

output:

YES 1 2 1 1 1 
YES 2 2 2 
YES 2 1 2 1 
YES 3 3 
YES 1 3 1 1 
YES 4 4 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 2 2 
YES 2 2 2 
YES 3 3 
YES 4 4 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 1 1 1 3 4 
YES 1 1 3 1 
YES 1 2 1 1 1 
YES 5 2 1 1 3 
YES 1 1 2 2 
YES 2 1 1 1 1 
YES 2 5 2 ...

result:

ok 50 testow OK.

Test #8:

score: 0
Accepted
time: 0ms
memory: 7168kb

input:

50
2
0 1
0 4
4
7 1
8 3
4 1
7 3
5
2 8
3 8
4 8
2 9
2 5
5
3 14
3 12
4 14
0 12
0 7
4
2 3
1 3
1 5
1 4
5
1 10
1 8
1 7
1 9
2 7
4
2 1
4 1
3 3
2 3
5
10 5
5 5
11 5
10 6
10 7
3
9 4
3 1
9 1
5
9 7
7 4
8 7
7 7
3 4
5
4 9
7 6
7 10
7 8
4 6
4
2 0
5 0
5 3
2 3
2
4 1
8 1
5
8 2
8 3
8 1
8 4
4 1
3
6 0
2 0
6 2
2
1 1
2 1
3
1...

output:

YES 3 3 
YES 2 1 3 1 
YES 1 1 1 3 3 
YES 1 2 1 3 5 
YES 3 1 1 1 
YES 1 1 1 1 4 
YES 2 3 1 1 
YES 1 5 2 1 3 
YES 3 6 3 
YES 1 3 1 1 4 
YES 3 2 2 2 3 
YES 3 3 3 3 
YES 4 4 
YES 1 1 1 1 4 
YES 2 4 2 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 2 2 
YES 1 1 2 
YES 2 1 1 2 
YES 1 1 1 1 2 
YES 3 3 
YES 3 1 1 1 
...

result:

ok 50 testow OK.

Test #9:

score: 0
Accepted
time: 2ms
memory: 6900kb

input:

50
4
4 2
6 2
4 0
6 0
2
0 4
0 1
4
8 5
8 4
5 3
8 3
5
9 6
11 9
10 9
9 9
12 6
3
9 10
6 10
6 4
5
8 2
11 1
10 1
8 1
9 1
4
6 8
9 5
6 5
9 8
2
1 3
2 3
3
3 2
2 2
1 2
4
0 3
0 0
0 1
0 2
2
2 1
0 1
3
4 4
4 3
5 3
4
1 4
2 3
1 1
1 3
5
0 1
1 0
1 1
2 0
0 0
2
6 2
3 2
4
4 2
3 2
5 2
3 3
2
3 0
2 0
3
3 1
4 1
5 1
4
4 6
2 5
...

output:

YES 2 2 2 2 
YES 3 3 
YES 1 1 3 1 
YES 3 1 1 1 4 
YES 3 3 6 
YES 3 4 1 1 1 
YES 3 3 3 3 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 2 2 
YES 1 1 2 
YES 2 1 2 1 
YES 1 1 1 2 1 
YES 3 3 
YES 1 1 3 2 
YES 1 1 
YES 1 1 1 
YES 1 2 1 3 
YES 1 1 1 1 2 
YES 1 2 1 2 5 
YES 2 1 1 
YES 1 1 1 1 
YES 1 1 1 1 2 
YES 1 ...

result:

ok 50 testow OK.

Test #10:

score: 0
Accepted
time: 2ms
memory: 6884kb

input:

50
4
4 7
5 7
4 5
4 3
5
2 5
3 2
2 2
2 3
3 5
2
2 1
1 1
3
4 0
3 0
2 0
4
2 1
3 1
4 1
5 1
2
2 0
0 0
3
8 1
7 1
7 2
4
5 0
6 0
3 0
5 1
5
1 3
1 4
0 3
0 1
0 4
2
5 4
5 7
2
3 6
2 6
3
5 4
7 4
6 4
4
4 7
5 7
6 7
3 7
2
1 4
1 2
2
3 3
3 0
2
2 0
1 0
3
0 0
0 2
0 1
4
0 0
3 0
1 0
2 0
5
4 3
4 4
4 6
4 5
4 7
5
1 3
3 0
2 3
0...

output:

YES 1 1 2 2 
YES 1 1 1 2 1 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 2 2 
YES 2 1 1 
YES 1 2 2 1 
YES 1 1 1 2 1 
YES 3 3 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 2 2 
YES 3 3 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 1 4 1 1 3 
YES 3 1 1 1 
YES 1 1 2 1 1 
YES 2 2 1 1 
YES 1 1 1 1 2 
YES 1 1 2 2 ...

result:

ok 50 testow OK.

Test #11:

score: 0
Accepted
time: 0ms
memory: 6832kb

input:

50
2
4 11
4 7
3
5 4
7 4
5 0
2
5 1
6 1
3
2 0
4 0
3 0
2
2 4
2 6
3
0 2
0 1
1 1
2
5 4
5 3
3
5 6
5 4
5 5
4
4 0
3 0
5 0
6 0
5
7 3
3 3
7 4
8 3
9 3
4
6 1
2 1
5 1
5 2
5
4 1
4 2
5 1
3 1
3 2
4
4 2
7 2
5 2
4 3
5
4 1
4 2
7 2
7 1
5 1
5
4 12
1 10
5 12
1 5
4 10
3
0 1
1 3
0 3
4
1 2
2 1
2 2
1 1
5
1 3
1 4
2 2
1 2
2 3
...

output:

YES 4 4 
YES 2 2 4 
YES 1 1 
YES 1 1 1 
YES 2 2 
YES 1 1 2 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 4 3 1 1 
YES 1 3 1 2 
YES 1 1 2 1 1 
YES 1 2 2 1 
YES 1 1 1 1 2 
YES 1 3 1 5 2 
YES 2 1 1 
YES 1 1 1 1 
YES 1 2 1 1 1 
YES 1 3 1 2 
YES 2 2 
YES 1 2 1 2 
YES 1 1 1 1 2 
YES 1 5 2 2 1 
YES 1 1 2 
YES 3 ...

result:

ok 50 testow OK.

Test #12:

score: 0
Accepted
time: 0ms
memory: 6904kb

input:

50
2
2 2
2 4
3
0 1
1 3
0 3
2
0 0
0 1
3
1 5
0 5
0 3
4
4 3
5 3
4 2
5 2
5
6 6
6 3
7 6
6 5
7 5
4
3 2
4 0
3 0
3 1
2
2 0
3 0
3
4 4
5 4
3 4
2
1 1
1 3
3
1 3
1 2
2 2
2
1 0
1 1
3
7 8
8 8
9 8
2
0 0
2 0
2
1 1
0 1
3
5 0
3 0
4 0
4
6 4
6 3
6 2
6 5
5
5 0
6 0
3 0
4 0
7 0
5
7 6
7 7
7 8
7 5
8 5
4
1 0
4 1
4 0
5 0
5
4 0...

output:

YES 2 2 
YES 2 1 1 
YES 1 1 
YES 1 1 2 
YES 1 1 1 1 
YES 1 2 1 1 1 
YES 1 3 1 1 
YES 1 1 
YES 1 1 1 
YES 2 2 
YES 1 1 2 
YES 1 1 
YES 1 1 1 
YES 2 2 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 1 1 1 1 4 
YES 3 2 1 1 
YES 1 2 1 1 1 
YES 1 1 2 2 
YES 1 1 1 2 1 
YES 1 1 2 
YES 1 1 1 1 
YES 2 2...

result:

ok 50 testow OK.

Test #13:

score: 0
Accepted
time: 0ms
memory: 6876kb

input:

32
2
0 0
0 1
2
5 1
6 1
3
5 9
5 7
5 8
4
7 0
8 2
9 0
7 2
5
6 9
6 10
7 8
6 8
7 9
3
2 1
3 0
2 0
4
0 2
1 1
0 1
1 2
2
1 2
3 2
3
7 1
9 1
9 2
2
2 0
2 1
2
6 0
7 0
3
3 6
3 7
4 6
4
7 3
6 4
7 4
6 3
2
1 3
1 2
2
4 2
4 1
2
5 0
5 1
3
1 1
3 1
2 1
4
6 1
5 1
3 1
4 1
5
6 0
8 0
7 0
5 0
4 0
2
2 1
2 3
3
8 4
8 6
8 8
2
5 4
...

output:

YES 1 1 
YES 1 1 
YES 1 1 1 
YES 2 1 3 1 
YES 1 2 1 1 1 
YES 1 2 1 
YES 1 1 1 1 
YES 2 2 
YES 2 1 1 
YES 1 1 
YES 1 1 
YES 1 1 2 
YES 1 1 1 1 
YES 1 1 
YES 1 1 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 1 1 1 1 1 
YES 2 2 
YES 2 2 2 
YES 3 3 
YES 4 4 
YES 1 1 
YES 1 1 1 
YES 1 1 1 1 
YES 2 2 
YES 3 3 
YE...

result:

ok 32 testow OK.

Test #14:

score: 0
Accepted
time: 3ms
memory: 6876kb

input:

50
19
4294 4169
4061 4177
4061 4170
4061 4546
4066 4169
4095 4169
5658 4169
4150 4169
4061 4172
4061 4224
4062 4169
4671 4169
4061 4313
4061 4190
4061 6753
4074 4169
4063 4169
4061 5156
4061 4169
23
1358 249
1351 841
1353 249
1351 303
1356 249
1351 346
1372 249
1360 249
1352 249
1760 249
1354 249
13...

output:

YES 377 13 2 610 8 55 4181 144 5 89 1 987 233 34 1597 21 3 1597 1 
YES 1 409 1 43 1 43 11 1 1 1001 1 11 183 11 1 1 1 43 183 10 43 409 1 
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
...

result:

ok 50 testow OK.

Test #15:

score: -100
Time Limit Exceeded

input:

50
6
4 1
6 1
5 1
8 1
9 1
7 1
6
7 9
7 10
7 7
3 2
7 8
3 7
6
6 3
5 3
7 3
6 1
4 3
4 1
6
6 2
3 2
6 4
4 5
5 5
3 5
6
11 3
12 3
10 4
10 3
3 3
10 7
6
2 8
1 9
3 8
4 8
1 13
1 8
6
5 2
4 3
6 2
4 2
5 3
8 2
6
6 3
7 2
9 2
6 4
6 2
6 7
6
2 4
1 4
1 5
1 3
2 5
2 3
6
4 1
2 2
3 1
2 3
3 2
2 1
6
1 0
3 1
3 0
3 2
1 2
2 2
6
4 ...

output:


result: