QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47427#4662. 二次整数规划问题feecle6418100 ✓504ms4032kbC++144.0kb2022-09-09 14:21:222022-09-09 14:21:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-09 14:21:24]
  • 评测
  • 测评结果:100
  • 用时:504ms
  • 内存:4032kb
  • [2022-09-09 14:21:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int N=3600;
const ll inf1=1e6,inf2=1e9,C=1e6;
struct E{
	int to,rev;
	ll flow;
};
int K,n,m,q,L[N+5],R[N+5],U[N+5],V[N+5],W[N+5],fa[N+5],sz[N+5];
int vst[N+5],dis[N+5],S,T,cur[N+5];
int gf(int x){
	return x==fa[x]?x:fa[x]=gf(fa[x]);
}
void Merge(int x,int y){
	x=gf(x),y=gf(y);
	if(x==y)return ;
	fa[x]=y,L[y]=max(L[y],L[x]),R[y]=min(R[y],R[x]),sz[y]+=sz[x];
}
vector<E> g[N+5];
void Add(int x,int y,ll z){
	g[x].push_back({y,g[y].size(),z});
	g[y].push_back({x,g[x].size()-1,0});
}
bool BFS(){
	queue<int> q;
	memset(dis,0x3f,sizeof(dis));
	dis[T]=0,q.push(T);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(E i:g[x]){
			int y=i.to;
			if(!g[y][i.rev].flow)continue;
			if(dis[y]>dis[x]+1){
				dis[y]=dis[x]+1;
				q.push(y);
				if(y==S)return 1;
			}
		}
	}
	return 0;
}
ll DFS(int x,ll fl){
	if(!fl||x==T)return fl;
	ll ret=0;
	for(int &i=cur[x];i<g[x].size();i++){
		int y=g[x][i].to;
		if(!g[x][i].flow||dis[x]!=dis[y]+1)continue;
		ll dlt=DFS(y,min(fl,g[x][i].flow));
		fl-=dlt,ret+=dlt,g[x][i].flow-=dlt,g[y][g[x][i].rev].flow+=dlt;
		if(!fl)return ret;
	}
	return ret;
}
ll Dinic(){
	ll ret=0;
	while(BFS())memset(cur,0,sizeof(cur)),ret+=DFS(S,inf2);
	return ret;
}
vector<pr> conv;
void dfs(int x){
	vst[x]=1;
	for(E i:g[x])if(i.flow&&!vst[i.to])dfs(i.to);
}
void Build(pr lef,pr rht){
	if(lef==rht)return ;
	int x1=lef.first,y1=lef.second,x2=rht.first,y2=rht.second;
	//cerr<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<'\n';
	//assert(x1<=x2),assert(y1>=y2);
	S=n+n+1,T=n+n+2;
	for(int i=1;i<=n;i++){
		if(gf(i)!=i||!L[i])continue;
		ll v2=0,v4=0;
		if(L[i]==2)v2=sz[i]*(y1-y2);
		if(R[i]==4)v4=sz[i]*(x2-x1);
		Add(S,i,v4),Add(i,i+n,v2+v4),Add(i+n,T,v2),Add(i+n,i,inf1);
	}
	for(int i=1;i<=m;i++){
		int x=gf(U[i]),y=gf(V[i]);
		if(x==y||!L[x]||W[i]!=1)continue;
		Add(x+n,y,inf1),Add(y+n,x,inf1);
	}
	Dinic();
	//选 2 有 y1-y2 收益
	//选 4 有 x2-x1 收益 
	dfs(S);
	int x3=0,y3=0;
	for(int i=1;i<=n;i++){
		if(gf(i)!=i||!L[i])continue;
		if(vst[S]&&!vst[i]&&L[i]==2)x3+=sz[i];
		if(vst[i+n]&&!vst[T]&&R[i]==4)y3+=sz[i];
	}
	for(int i=1;i<=T;i++)g[i].clear(),vst[i]=0;
	if((y3-y1)*(x3-x2)==(y3-y2)*(x3-x1))return ;
	conv.push_back(pr(x3,y3));
	Build(lef,pr(x3,y3)),Build(pr(x3,y3),rht);
}
void Solve(){
	scanf("%d%d%d%d",&K,&n,&m,&q);
	for(int i=1;i<=n;i++)scanf("%d%d",&L[i],&R[i]),fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&U[i],&V[i],&W[i]);
		if(!W[i])Merge(U[i],V[i]);
	}
	for(int cnt=1;cnt<=n;cnt++){
		for(int i=1;i<=m;i++){
			int x=gf(U[i]),y=gf(V[i]);
			if(!W[i]||x==y)continue;
			R[y]=min(R[y],R[x]+W[i]);
			L[y]=max(L[y],L[x]-W[i]);
			R[x]=min(R[x],R[y]+W[i]);
			L[x]=max(L[x],L[y]-W[i]);
		}
	}
	int mus[10]={0},mx2=0,mx4=0,all=0;
	for(int i=1;i<=n;i++){
		if(gf(i)!=i)continue;
		if(R[i]<=2)mus[R[i]]+=sz[i],L[i]=R[i]=0;
		else if(L[i]>=4)mus[L[i]]+=sz[i],L[i]=R[i]=0;
		else if(L[i]==R[i])mus[L[i]]+=sz[i],L[i]=R[i]=0;
		else {
			L[i]=max(L[i],2),R[i]=min(R[i],4);
			if(L[i]==2)mx2+=sz[i];
			if(R[i]==4)mx4+=sz[i];
			all+=sz[i];
		}
		//剩下的只会是 [2,3] [3,4] [2,3,4]
	}
	conv.push_back(pr(0,mx4));
	conv.push_back(pr(mx2,0));
	conv.push_back(pr(0,0));
	Build(pr(0,mx4),pr(mx2,0));
	for(int i=1;i<=q;i++){
		ll ans=0,v[10]={0};
		for(int j=2;j<K;j++)scanf("%lld",&v[j]);
		for(pr j:conv){
			int c2=j.first,c4=j.second,rl[10]={0};
			memcpy(rl,mus,sizeof(rl)),rl[2]+=c2,rl[4]+=c4,rl[3]+=all-c2-c4;
			ll sum=0;
			for(int k=2;k<K;k++)sum+=v[k]*rl[k];
			for(int k=1;k<=K;k++)
				for(int l=1;l<=K;l++)
					if(abs(k-l)<=1)sum+=C*rl[k]*rl[l];
			ans=max(ans,sum);
		}
		cout<<ans<<'\n';
	}
	for(int i=0;i<=max(m,2*n+2);i++)L[i]=R[i]=U[i]=V[i]=W[i]=fa[i]=sz[i]=vst[i]=0;
	conv.clear();
	//cerr<<"PP\n";
}
int main(){
	//freopen("qip5.in","r",stdin);
	//freopen("1.out","w",stdout);
	int t;
	scanf("%*d%d",&t);
	while(t--)Solve(); 
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4
Accepted
time: 1ms
memory: 3844kb

input:

1 10
3 9 0 115
1 3
1 3
1 1
2 2
2 3
2 2
3 3
1 2
2 3
658203418123
6905620
622765945476
252875716229
2996822
8657162
18477223
830371309382
7361676
19157395
476213860310
145256
465830672653
570192000514
19624112
627396394982
247771396526
14196803
9325384
431820605418
625748891934
8219776
572139911916
25...

output:

4607502926861
127339340
4359440618332
1770209013603
99977754
139600134
208340561
5812678165674
130531732
213101765
3333576022170
80016792
3260893708571
3991423003598
216368784
4391853764874
1734478775682
178377621
144277688
3022823237926
4380321243538
136538432
4005058383412
1791843781758
4801409806...

result:

ok 200 numbers

Test #2:

score: 6
Accepted
time: 102ms
memory: 3948kb

input:

2 600
3 600 596 157061
1 2
1 2
1 1
1 2
2 3
3 3
2 3
1 2
1 1
2 2
1 2
1 3
1 3
3 3
1 3
1 2
1 3
2 2
2 2
1 1
1 1
2 3
1 2
1 2
2 2
1 1
2 3
2 3
2 3
1 2
2 3
1 3
1 2
1 3
1 2
1 2
1 1
1 2
1 3
1 2
1 3
1 3
1 2
1 2
1 1
2 3
1 2
2 3
1 3
1 3
1 3
2 3
1 1
1 3
3 3
2 3
2 2
1 1
1 3
2 3
2 3
1 2
1 1
2 3
2 2
1 3
1 3
2 3
2 2
1...

output:

357297193241
164861912841578
355443266996
436251520919042
359017128828836
168655137304175
30058706198420
82741026078026
336656296298258
188609622449948
392615357377049
351706079357
66989601391688
351251184653
28329778879046
15715555030016
84778669719620
458359958133503
216874786403294
355556711600
2...

result:

ok 300000 numbers

Test #3:

score: 4
Accepted
time: 0ms
memory: 3680kb

input:

3 10
4 8 20 108
1 3
1 3
4 4
2 3
1 3
4 4
3 4
4 4
6 1 2
1 2 3
1 8 3
3 5 3
6 3 3
6 7 3
1 3 3
4 5 1
6 2 3
3 2 3
4 1 3
8 1 1
4 3 2
1 2 0
1 4 1
7 6 3
5 7 1
3 1 1
7 7 3
6 5 3
401193240968 995208538459
353171538452 1968621
456070818347 731730207166
246878450904 1124586
1616052 1433040
874305670186 700986875...

output:

4976106692295
706400982767
3658715035830
493812275566
71165200
3851623966254
1712981554611
4680214558540
3756347800480
68770915
1805949583822
4264753967820
4343656944695
23262510920
2509677872350
1490957084650
1345739922570
4965012949965
4628363528495
312292969856
1377323436800
2485176127355
1321643...

result:

ok 200 numbers

Test #4:

score: 6
Accepted
time: 168ms
memory: 4032kb

input:

4 600
4 600 1294 157227
2 3
2 4
3 4
2 2
1 1
3 3
1 3
1 4
1 4
2 2
3 3
1 2
2 3
3 3
1 4
2 4
1 4
4 4
3 3
2 3
2 2
1 3
2 4
1 3
2 3
1 4
3 4
4 4
3 3
1 2
4 4
3 4
1 3
1 2
2 4
3 3
1 4
2 3
2 3
1 1
3 4
3 3
1 2
1 2
3 3
1 2
2 2
2 4
2 3
3 4
1 3
1 4
1 2
1 4
2 4
2 4
1 3
2 2
1 4
1 3
1 3
2 3
1 3
3 4
1 4
2 3
1 1
1 2
1 3
...

output:

326330874986634
266023872353957
308099862643100
255774576036952
293270434851554
210303324031298
344358231690686
419354488333622
147132960949905
211939860140544
329354998523166
275924958616566
133243396486754
252765431548503
85209484242580
57028056033142
338842309366822
251310971332184
10045781295551...

result:

ok 300000 numbers

Test #5:

score: 5
Accepted
time: 2ms
memory: 3872kb

input:

5 10
5 9 17 242
1 1
2 2
1 4
4 4
1 3
3 5
1 3
1 3
3 5
4 2 2
1 1 3
7 4 3
7 8 2
4 3 1
2 9 3
6 2 1
6 3 2
8 6 1
3 5 2
3 8 1
1 1 1
7 8 4
9 2 3
4 7 1
2 6 3
9 5 1
271928445423 798305139120 796785695833
722910066727 229906468430 810783986581
919517620309 866805930321 859380035316
176315418286 453811728241 628...

output:

5858609975976
4074948900190
7085221617527
3876818744295
4507271032123
2054158710691
4333392103083
2451799633603
4026871106497
3782760832589
4274244788793
6611329128388
3722519724501
3485998917225
6702892039882
3814332936486
6310623579669
5477335448090
6756892536749
4925436707444
4093958151936
354344...

result:

ok 300 numbers

Test #6:

score: 4
Accepted
time: 0ms
memory: 3880kb

input:

6 15
5 15 11 402
2 5
2 5
2 4
2 3
2 4
1 4
4 4
2 4
2 4
2 5
1 1
2 5
1 1
5 5
1 5
1 14 2
15 12 0
12 9 1
1 6 0
12 10 1
1 10 1
2 5 0
9 11 1
6 5 0
4 7 1
12 3 0
910152097519 175243574197 154352789350
426002200739 389601768514 887712385039
303341543782 261172159164 196762016508
618569610914 591630135479 30705...

output:

6491646245449
8198548970068
3322835075020
6976785194597
6997278081397
9759905189156
10668370731824
9543951559191
4962246323512
6896083141018
7191797067417
6097350493430
6768286155956
6455151087183
2758233043168
5198123440630
4155027849858
8208487080454
6199056371326
7004825542541
7001361616614
12397...

result:

ok 500 numbers

Test #7:

score: 4
Accepted
time: 3ms
memory: 3792kb

input:

7 25
5 25 21 595
3 3
2 4
2 5
1 5
1 4
1 4
1 2
2 4
1 1
4 4
2 4
5 5
2 4
1 3
2 5
2 4
2 5
1 4
2 4
1 5
2 4
2 4
2 4
2 5
1 1
15 16 0
18 2 1
13 16 0
5 17 0
18 23 0
13 10 1
17 2 1
16 23 0
19 12 2
6 21 1
14 21 1
8 21 0
24 10 1
5 7 1
19 7 1
11 17 0
3 17 0
20 14 0
14 22 0
4 6 0
6 24 0
474744872990 522331829125 3...

output:

11270997111904
7656988988471
6935814058732
19456706150941
17014520576984
15605454140985
9510393650483
9376065338251
11264421703227
13649797017496
16961418089272
12670941963680
10168627276737
11529237359655
11041511414513
20561858863404
15154993547066
19534066001566
19114579166771
12193233872597
1671...

result:

ok 750 numbers

Test #8:

score: 6
Accepted
time: 4ms
memory: 3740kb

input:

8 50
5 49 50 774
2 5
2 4
1 3
1 5
1 4
2 5
1 4
2 5
2 4
2 4
3 4
4 4
2 5
1 5
2 4
2 5
1 4
2 5
2 4
2 4
2 5
2 4
1 5
2 4
1 5
1 5
1 5
5 5
2 5
3 5
2 4
1 4
2 5
2 4
1 1
2 4
2 4
1 4
2 5
1 4
2 4
1 4
2 4
2 5
1 5
1 5
2 3
1 1
1 4
38 35 2
25 14 0
31 39 1
36 20 0
5 31 1
34 45 0
44 4 1
37 6 0
46 39 1
13 39 1
18 39 1
34...

output:

16411855359820
30862438095555
35358148741245
24243018950274
13437400941943
40856902713918
34811749852591
26463659881497
36613648932316
38079649947694
29634500414283
30333666053770
17980594056385
34202105236092
24022893381858
32108332820386
22025131074467
29959962411915
15909995288809
32556544115411
...

result:

ok 1000 numbers

Test #9:

score: 6
Accepted
time: 5ms
memory: 3888kb

input:

9 80
5 80 86 1152
2 4
2 5
1 4
1 5
2 4
4 5
4 4
1 5
2 4
1 4
2 5
2 5
2 4
2 3
1 4
2 5
1 4
1 5
1 5
1 4
2 4
1 3
2 5
1 5
1 4
1 4
1 4
1 4
2 4
2 5
1 5
2 5
1 5
1 4
1 2
2 4
2 4
1 4
1 4
2 5
1 4
1 4
2 4
1 5
2 5
3 4
2 4
2 4
1 5
2 5
1 5
2 4
2 5
2 4
2 5
2 5
2 5
1 1
1 5
2 5
2 5
5 5
2 4
2 2
3 4
1 4
1 5
2 4
2 4
1 4
1 ...

output:

43173336173321
48379179671216
61732155022844
52475055738777
60424658579039
45788700631742
43656652426991
39954033905650
21565724979888
50071822153180
53569308867112
48967008468227
48513070292990
57479392675689
73226577611663
54978429802800
43966072669984
26054060892577
45070681723753
50418256793182
...

result:

ok 1500 numbers

Test #10:

score: 5
Accepted
time: 1ms
memory: 3864kb

input:

10 120
5 120 130 1532
1 5
1 5
2 5
2 5
2 4
1 5
2 4
2 4
2 3
3 4
2 4
2 4
1 5
2 4
2 4
1 5
2 4
1 5
2 4
2 5
1 5
1 4
1 1
2 4
2 5
1 5
2 5
2 5
1 5
1 5
1 5
3 4
1 4
2 5
2 4
2 4
2 5
1 5
1 4
2 5
2 5
1 5
2 5
2 5
2 5
2 4
3 5
2 4
2 5
3 5
1 4
1 5
2 5
2 5
3 5
2 4
2 4
1 5
2 5
2 4
2 5
1 4
1 4
1 5
1 5
2 5
2 4
1 5
2 5
1 ...

output:

63602867168600
101731196482014
92305249049498
73775533697530
110522467058055
92008233794400
48928399002602
88564264676794
96744974112036
71633177160737
70507065710491
103313034017851
17071162562969
84270703570104
57631578957348
79151795566799
77619165477540
77620444072322
95247655746342
693106356066...

result:

ok 2000 numbers

Test #11:

score: 3
Accepted
time: 5ms
memory: 3932kb

input:

11 200
5 200 0 6331
1 1
1 2
1 3
1 1
3 3
1 2
1 1
4 5
4 4
1 5
2 2
1 2
5 5
5 5
3 4
2 5
2 3
1 4
2 3
2 3
2 3
2 4
1 2
1 5
1 4
1 3
2 3
1 2
3 3
3 4
3 5
2 5
1 4
1 3
2 5
3 5
3 5
1 5
1 2
1 1
2 4
1 2
1 2
2 5
1 2
1 2
2 5
4 4
2 5
1 4
3 4
2 4
2 4
1 4
3 4
2 5
3 4
2 3
2 5
1 4
5 5
2 4
3 4
1 1
4 4
1 4
4 5
3 4
2 4
2 4
...

output:

119342637257251
128388173707220
111084996328359
157252088885495
175756234861472
143899687055552
116303911085186
132692078362401
139773506437735
96146670759328
152118969964169
128730360620264
141157148907793
144718305928451
124191758001235
122728868138622
147230654034856
148509060105740
3759212537773...

result:

ok 8000 numbers

Test #12:

score: 4
Accepted
time: 27ms
memory: 3780kb

input:

12 400
5 399 0 24008
5 5
3 5
4 5
5 5
3 5
4 5
3 4
4 5
4 5
1 3
3 5
2 5
1 4
1 2
1 5
2 5
2 5
3 5
1 3
5 5
3 5
2 4
1 2
3 3
2 4
3 3
1 2
4 4
5 5
1 5
2 5
1 2
3 4
2 5
2 2
1 4
1 1
2 2
1 3
2 4
3 3
1 4
1 1
1 3
3 5
5 5
3 4
1 5
2 4
1 4
3 4
3 5
2 5
1 4
1 4
2 3
2 5
1 5
1 2
1 2
2 3
3 4
2 5
1 5
2 5
2 2
1 3
3 4
4 4
3 5...

output:

273398697481417
275581543494465
112639763389498
208591921347822
274577497610718
171159870741590
220217416399128
197872703369255
118832257760004
315482946084500
319178062757912
326412510236264
261165602990663
121829237782274
255203148475584
148802450822224
268667153706950
244111407530824
263155939708...

result:

ok 30000 numbers

Test #13:

score: 5
Accepted
time: 134ms
memory: 3904kb

input:

13 600
5 599 0 161496
1 5
1 2
2 4
1 1
1 3
1 3
5 5
2 4
2 2
1 5
1 2
3 3
1 3
4 4
1 2
1 5
2 5
5 5
2 3
2 5
4 5
3 3
2 5
4 4
4 4
1 2
3 3
3 4
1 1
3 5
4 5
4 4
2 2
1 5
3 5
1 2
2 2
3 5
1 1
2 5
4 4
4 4
1 1
1 4
3 3
2 5
1 3
3 3
3 5
1 5
1 3
1 2
2 5
3 5
3 4
5 5
1 2
1 5
2 4
3 5
1 4
4 4
2 3
2 4
1 1
1 5
4 4
3 4
1 2
2 ...

output:

335749178644070
495434475852526
342993330210422
392748473892963
299682715380817
392612411623920
459962505190307
180543144504562
299105373318074
422840698814929
212879459848175
365771452476895
256332484121325
521542258132687
436358315944947
109466575109592
70509758413125
208555381020119
2579759521083...

result:

ok 200000 numbers

Test #14:

score: 3
Accepted
time: 11ms
memory: 3944kb

input:

14 200
5 199 10 6319
1 3
1 1
4 5
2 5
1 2
3 3
1 4
1 5
2 5
2 5
2 5
1 4
2 2
3 3
5 5
3 3
2 4
4 5
2 2
3 3
2 5
3 5
4 4
1 5
3 5
1 2
1 4
2 4
1 3
1 3
3 5
3 4
1 5
1 2
1 3
4 4
2 4
1 3
4 5
1 4
2 5
1 3
1 2
2 4
2 3
2 3
2 4
3 5
2 5
1 5
3 5
1 5
1 5
1 3
3 4
2 3
4 5
1 3
4 5
2 2
3 4
2 5
2 2
2 5
2 5
1 3
2 4
4 5
3 4
3 4...

output:

133979833559952
163474467236312
149482468595017
159109645546715
142848831773033
114538412895062
92382303249118
142094731168341
146006313836820
138898377533718
90366203850164
110399618141096
93414151473382
104666227533559
144480204652038
120453498522911
46893485262916
136282254223986
130276085181282
...

result:

ok 8000 numbers

Test #15:

score: 4
Accepted
time: 24ms
memory: 3944kb

input:

15 400
5 399 10 23992
4 5
1 2
3 5
4 5
3 4
2 5
2 4
1 2
2 5
1 1
4 5
2 2
4 5
4 5
1 4
3 5
1 3
2 3
1 4
2 5
2 3
1 2
1 3
2 3
1 2
2 3
1 2
2 5
4 4
2 4
3 5
3 4
3 5
5 5
1 5
3 5
3 4
3 5
3 5
2 5
3 3
1 3
1 1
1 5
1 5
1 1
2 5
1 4
1 4
1 4
3 3
1 3
4 5
1 5
2 5
4 4
3 4
1 5
1 3
2 5
2 4
1 4
2 4
5 5
4 5
3 5
3 3
2 5
1 1
2 ...

output:

281666614191992
254694150419229
254836768267886
179835544743370
201712613846799
193621409653849
288127493447937
218076686570948
270820114482413
257144906290122
231669788416951
291639238399134
307597327780721
229236438296358
289980448246619
273629412285779
271505517570023
297464673341855
167314151511...

result:

ok 30000 numbers

Test #16:

score: 4
Accepted
time: 110ms
memory: 3904kb

input:

16 600
5 600 10 161360
2 4
4 5
3 4
3 3
2 3
1 2
2 3
3 4
1 2
3 4
1 3
1 3
1 1
2 2
2 5
2 4
4 4
3 5
2 5
3 4
1 4
3 3
1 5
2 4
2 3
4 5
1 1
4 5
4 5
2 5
2 3
2 5
1 4
3 3
2 4
1 1
3 4
1 3
3 5
3 4
3 5
4 5
2 2
1 3
2 3
1 5
2 2
1 3
2 5
4 5
2 4
2 2
4 5
1 2
3 4
4 5
1 2
2 4
3 5
2 2
2 5
2 3
1 5
3 4
1 2
2 5
4 4
4 4
1 2
2...

output:

181278926200419
386453914757203
386319439875542
493317511242192
487083543495960
402817134226612
83961490405313
277137634721699
226964737963217
344548710346617
349989846610085
528618991799189
460710926276896
378705613479919
432484524569292
470691495927259
235451741825977
405583690014834
3336355728953...

result:

ok 200000 numbers

Test #17:

score: 4
Accepted
time: 82ms
memory: 3836kb

input:

17 120
5 119 355 81330
3 5
3 5
3 5
1 5
1 3
3 3
1 2
2 5
2 2
3 4
1 5
3 5
4 5
3 3
4 5
3 4
3 5
2 5
1 4
2 3
4 4
2 5
1 3
1 4
1 5
4 5
5 5
3 4
2 5
2 4
4 5
1 3
3 4
2 5
4 5
1 4
1 2
3 3
1 2
1 5
1 1
2 2
4 4
2 3
3 3
3 4
5 5
1 2
1 2
3 5
3 5
4 5
1 5
2 5
1 4
2 4
2 2
3 3
3 5
1 4
1 1
3 3
3 5
1 4
5 5
3 5
5 5
4 5
2 4
4...

output:

66198382514252
59622159077969
60827005109865
46118195591083
66771374223710
48831804665381
79608131752009
31968284755062
94127991928758
45944596201478
32119458879636
70443862946816
74193874490723
70832357442367
61755956068141
57232920654146
18449977428589
66922135462574
59076425039328
74141179956533
...

result:

ok 100000 numbers

Test #18:

score: 5
Accepted
time: 165ms
memory: 3772kb

input:

18 150
5 149 393 162466
1 3
5 5
1 2
2 5
2 5
3 5
4 5
1 3
2 4
2 3
3 4
2 3
2 3
2 4
1 2
5 5
2 4
2 4
2 5
4 5
3 5
2 4
4 5
1 2
4 5
2 3
1 4
3 5
1 3
1 2
3 4
1 5
2 4
3 3
2 4
1 5
2 4
1 5
2 3
5 5
1 4
2 4
2 3
1 5
1 1
4 5
3 3
3 3
1 3
4 5
4 5
2 5
4 4
2 2
1 4
3 4
2 2
1 5
1 3
1 5
2 3
1 3
2 5
3 5
3 4
2 3
2 4
4 5
3 5
...

output:

90462993219411
92196171930641
105558329776600
109829303449099
78209529286435
105944215391721
93991905015011
88209421536733
86612481454766
88209979384243
81754437866348
54795015659628
71273911152566
62949966302086
54902672601916
76583096660954
89991650399327
98772141539034
70371810015192
276635801659...

result:

ok 200000 numbers

Test #19:

score: 5
Accepted
time: 213ms
memory: 3780kb

input:

19 180
5 180 289 243700
2 3
1 5
2 3
1 4
4 5
2 4
1 1
1 5
2 5
3 5
4 5
1 2
2 4
4 5
1 5
2 3
2 4
2 4
1 2
2 4
3 3
3 5
2 5
2 2
2 3
1 2
5 5
2 5
1 3
2 5
3 5
4 5
1 5
3 4
3 5
1 3
3 4
1 4
2 5
2 3
3 5
3 4
2 5
1 4
2 4
3 3
1 2
5 5
3 5
3 5
4 5
1 2
1 3
1 4
2 2
2 2
1 4
2 4
1 4
2 4
1 1
2 2
1 3
1 4
2 2
3 4
2 4
1 5
1 3
...

output:

82357639672559
109278227945149
47909684545677
106819187228408
125097491886803
96807857495463
60437316712917
62518834560561
127161460194292
73561810777818
85468039484735
56463515385768
90838174309695
126999937276284
91926606344616
81621959364724
71164295011060
107726310839415
62755972690698
135795857...

result:

ok 300000 numbers

Test #20:

score: 5
Accepted
time: 84ms
memory: 3956kb

input:

20 300
5 300 340 40300
1 4
2 4
1 5
2 5
1 4
2 4
2 5
1 4
1 4
1 4
2 4
1 4
2 4
2 5
4 4
1 4
2 4
2 4
2 4
2 5
1 4
2 4
1 4
2 5
2 4
2 5
2 4
2 4
1 5
2 4
1 5
2 5
1 5
1 5
2 4
2 4
2 5
1 5
1 5
1 4
1 4
1 4
1 4
1 5
1 5
2 4
2 4
2 5
2 4
2 5
1 5
2 4
1 4
1 4
1 4
2 4
1 4
3 5
2 3
1 4
2 4
1 5
1 4
2 5
2 4
1 5
1 4
2 5
2 5
2...

output:

218130940674637
140726103406404
222657546947880
104930864471334
175682167130420
261194346998352
210878096255632
287022367774339
183080954101912
224846557729055
217076909443111
238241480685678
253853170527494
185754102697537
250938400107558
232108311171164
219049442495196
205601212531212
182076296082...

result:

ok 50000 numbers

Test #21:

score: 4
Accepted
time: 156ms
memory: 3908kb

input:

21 450
5 450 498 80658
2 5
2 4
2 5
2 4
1 5
2 5
1 5
2 4
2 4
4 4
1 5
1 5
2 4
2 5
1 4
2 4
1 5
2 4
1 4
1 5
1 4
2 5
2 4
1 4
2 4
1 4
2 4
2 4
1 5
2 5
1 4
1 4
2 4
2 5
1 5
1 4
2 4
1 4
2 5
2 5
2 5
2 5
2 4
1 1
2 5
1 4
2 5
1 5
2 5
1 5
2 5
2 4
2 5
1 4
2 5
1 3
1 4
2 4
2 5
2 5
2 4
2 4
1 4
2 4
1 5
1 4
1 4
1 3
1 5
2...

output:

348537382085321
343294985626014
373983520542463
340960976831875
398780686844023
424638057048250
208785160972457
98663085451259
343459816079694
305202335549029
332141994036632
379397559681111
49084384728407
360703253246668
187128021523960
350269908280291
406350955644555
305184300973585
27218854103732...

result:

ok 100000 numbers

Test #22:

score: 4
Accepted
time: 504ms
memory: 3892kb

input:

22 600
5 600 690 242382
1 4
2 4
1 4
1 4
1 5
1 4
1 5
2 5
1 5
2 5
1 5
1 4
1 4
1 5
1 5
2 4
1 4
1 5
2 5
2 4
1 4
2 3
2 5
1 4
2 4
2 4
2 5
2 4
1 5
2 5
2 4
2 4
1 4
1 5
2 5
2 5
3 4
3 5
2 4
2 5
1 3
2 4
1 5
1 5
1 5
2 5
2 5
2 5
1 5
1 4
1 5
1 5
3 5
2 4
1 5
1 4
1 4
2 5
1 4
2 4
1 4
1 4
1 5
2 4
1 5
2 5
1 5
1 4
1 4
...

output:

464440385956615
411871996194468
492245570890866
290012140920905
407044073875942
413729220334542
480514246642687
369451460117159
275338979512217
525165307508844
374042621417122
244184176142816
343846931342235
562186934927726
573816960849201
494203884165926
495537198495828
548944831050759
346630760325...

result:

ok 300000 numbers

Extra Test:

score: 0
Extra Test Passed