QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53555#4662. 二次整数规划问题not_so_organic100 ✓376ms3192kbC++204.0kb2022-10-05 13:22:372022-10-05 13:23:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-05 13:23:01]
  • 评测
  • 测评结果:100
  • 用时:376ms
  • 内存:3192kb
  • [2022-10-05 13:22:37]
  • 提交

answer

#include<cstdio>
#include<cctype>
#include<vector>

#define maxn 666

const int inf=1e9;
const long long INF=1e18;

template<class T>

inline T read(){
	T r=0,f=0;
	char c;
	while(!isdigit(c=getchar()))f|=(c=='-');
	while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
	return f?-r:r;
}

template<class T>

inline T min(T a,T b){
	return a<b?a:b;
}

template<class T>

inline T max(T a,T b){
	return a>b?a:b;
}

template<class Tmp,int MAXN,int MAXM,Tmp INF>

struct MF{

	struct E{
		int v;
		Tmp c;
		int nxt;
		E() {}
		E(int v,Tmp c,int nxt):v(v),c(c),nxt(nxt) {}
	}e[MAXM<<1];

	int n,s,t,hd,tl,s_e,head[MAXN],cur[MAXN],lev[MAXN],q[MAXN];

	inline void a_e(int u,int v,Tmp c){
		e[++s_e]=E(v,c,head[u]);
		head[u]=s_e;
	}

	inline void add(int u,int v,Tmp c){
		a_e(u,v,c),a_e(v,u,0);
	}

	inline void init(int N,int S,int T){
		n=N,s=S,t=T,s_e=1;
		for(int i=1;i<=n;i++)head[i]=0;
	}

	bool bfs(){
		for(int i=1;i<=n;i++)
			lev[i]=0,cur[i]=head[i];
		hd=0,tl=1,q[++tl]=s,lev[s]=1;
	    while(hd^tl){
			int u=q[++hd];
			for(int i=head[u];i;i=e[i].nxt){
				int v=e[i].v;
				if(!e[i].c||lev[v])continue;
				lev[v]=lev[u]+1,q[++tl]=v;
				if(v==t)return true;
			}
		}
		return false;
	}

	Tmp dfs(int u,Tmp f){
		if(u==t)return f;
		int d=0,used=0;
		for(int &i=cur[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(!e[i].c||lev[v]!=lev[u]+1)continue;
			if(!(d=dfs(v,min(f-used,e[i].c))))continue;
			e[i].c-=d,e[i^1].c+=d,used+=d;
			if(used==f)break;
		}
		if(!used)lev[u]=0;
		return used;
	}

	inline Tmp solve(){
	    Tmp flow=0;
		while(bfs())
		    flow+=dfs(s,INF);
		return flow;
	}

};

MF<int,maxn<<2,maxn<<4,inf> mf;

int K,n,m,t,cnt[11],l[maxn],r[maxn],f[maxn],size[maxn];

int p[maxn<<2],q[maxn<<2],b[maxn<<2];

std::vector<std::pair<int,int> > hull;

int find(int x){
	return x^f[x]?f[x]=find(f[x]):x;
}

#define x first
#define y second

template<class T>

void solve(T a,T b){
	int X=a.y-b.y;
	int Y=b.x-a.x;
	int s=2*n+1,t=s+1;
	mf.init(t,s,t);
	for(int i=1;i<=n;i++){
		if(l[i]<2||r[i]>K-1||f[i]!=i)continue;
		mf.add(s,i,l[i]==2?Y*size[i]:inf);
		if(K==5)mf.add(i,i+n,l[i]<=3&&r[i]>=3?(X+Y)*size[i]:inf);
		mf.add(i+n,t,r[i]==4?X*size[i]:inf);
	}
	for(int i=1;i<=m;i++){
		int u=find(p[i]);
		int v=find(q[i]);
		if(::b[i]>1||u==v)continue;
		mf.add(u+n,v,inf),mf.add(v+n,u,inf);
	}
	mf.solve();
	T c={0,0};
	for(int i=1;i<=n;i++){
		if(l[i]<2||r[i]>K-1||f[i]!=i)continue;
		if(!mf.lev[i])c.x+=size[i];
		if(mf.lev[i+n])c.y+=size[i];
	}
	if(!((c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y)))return;
	hull.push_back(c),solve(a,c),solve(c,b);
}

#undef x
#undef y

inline void query(){
	long long ans=-INF;
	static long long val[11];
	for(int i=2;i<K;i++)
		val[i]=read<long long>();
	for(auto P:hull){
		cnt[2]=P.first,cnt[K-1]=P.second;
		if(K==5)cnt[3]=n-cnt[1]-cnt[2]-cnt[4]-cnt[5];
		long long s=0,sum=0;
		for(int i=1;i<=K;i++){
			s+=cnt[i]*(cnt[i]+cnt[i+1]*2);
			sum+=cnt[i]*val[i];
		}
		sum+=s*1000000;
		ans=max(ans,sum);
	}
	printf("%lld\n",ans);
}

inline void work(){
	K=read<int>();
	n=read<int>();
	m=read<int>();
	int t=read<int>();
	for(int i=1;i<=K;i++)cnt[i]=0;
	for(int i=1;i<=n;i++){
		l[i]=read<int>();
		r[i]=read<int>();
	}
	for(int i=1;i<=m;i++){
		p[i]=read<int>();
		q[i]=read<int>();
		b[i]=read<int>();
	}
	for(int T=1;T<=n;T++)
		for(int i=1;i<=m;i++){
			int x=p[i],y=q[i],w=b[i];
			l[x]=max(l[x],l[y]-w),l[y]=max(l[y],l[x]-w);
			r[x]=min(r[x],r[y]+w),r[y]=min(r[y],r[x]+w);
		}
	int mxl=0,mxr=0;
	for(int i=1;i<=n;i++){
		if(r[i]>1&&l[i]<K)
			l[i]=max(l[i],2),r[i]=min(r[i],K-1);
		if(l[i]==r[i])cnt[l[i]]++;
		mxl+=(l[i]==2),mxr+=(r[i]==K-1);
	}
	for(int i=1;i<=n;i++)
	    f[i]=i,size[i]=0;
	for(int i=1;i<=m;i++)
		if(!b[i])f[find(p[i])]=find(q[i]);
	for(int i=1;i<=n;i++)size[find(i)]++;
	hull={{cnt[2],cnt[K-1]},{cnt[2],mxr},{mxl,cnt[K-1]}};
	if(K==5)solve(hull[1],hull[2]);
	while(t--)query();
}

int main(){
	read<int>();
	int t=read<int>();
	while(t--)work();
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4
Accepted
time: 2ms
memory: 3120kb

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: 42ms
memory: 3152kb

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: 2ms
memory: 3004kb

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: 92ms
memory: 3164kb

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: 3128kb

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: 2ms
memory: 3008kb

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: 3124kb

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: 3ms
memory: 3148kb

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: 4ms
memory: 3124kb

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: 0ms
memory: 3152kb

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: 2ms
memory: 3116kb

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: 17ms
memory: 3028kb

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: 71ms
memory: 3152kb

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: 8ms
memory: 3136kb

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: 10ms
memory: 3056kb

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: 93ms
memory: 3048kb

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: 45ms
memory: 3168kb

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: 100ms
memory: 3192kb

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: 99ms
memory: 3120kb

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: 51ms
memory: 3140kb

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: 121ms
memory: 3136kb

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: 376ms
memory: 3176kb

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