QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673655#4662. 二次整数规划问题alexl100 ✓363ms4064kbC++144.7kb2024-10-25 06:56:292024-10-25 06:56:29

Judging History

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

  • [2024-10-25 06:56:29]
  • 评测
  • 测评结果:100
  • 用时:363ms
  • 内存:4064kb
  • [2024-10-25 06:56:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long
const int _ = 603 , __ = 3003 , G = 1e6;
int C , K , N , M , Q , L[_] , R[_] , S[__] , T[__] , X[__] , cnt[6] , V[6] , sz[_] , bel[_]; 
vector < int > id[_];

int calc(){
	int sum = 0; for(int i = 2 ; i <= K - 1 ; ++i) sum += V[i] * cnt[i];
	for(int i = 1 ; i <= K ; ++i) for(int j = 1 ; j <= K ; ++j) if(abs(i - j) <= 1) sum += G * cnt[i] * cnt[j];
	return sum;
}

struct pii{
	int x , y; pii(int _x = 0 , int _y = 0):x(_x) , y(_y){}
	friend pii operator -(pii p , pii q){return pii(p.x - q.x , p.y - q.y);}
	pii rot(){return pii(y, -x);}
	friend int operator %(pii p , pii q){return p.x * q.y - p.y * q.x;}
}; vector < pii > hull; vector < vector < int > > hull_val;

const int MAX = 5e4 + 7; struct Edge{int end , upEd , f;}Ed[MAX];
int head[__] , cur[__] , dep[__] , cntEd , tar; queue < int > q;
void init(int t){tar = t; memset(head , 0 , sizeof(int) * (tar + 1)); cntEd = 1;}
void addEd(int x , int y , int c){Ed[++cntEd] = (Edge){y , head[x] , c}; head[x] = cntEd;}
void addE(int x , int y , int c){addEd(x , y , c); addEd(y , x , 0);}

bool bfs(){
	memset(dep , 0 , sizeof(int) * (tar + 1)); memcpy(cur , head , sizeof(int) * (tar + 1)); while(!q.empty()) q.pop();
	q.push(0); dep[0] = 1;
	while(!q.empty()){
		int t = q.front(); q.pop();
		for(int i = head[t] ; i ; i = Ed[i].upEd)
			if(Ed[i].f && !dep[Ed[i].end]){dep[Ed[i].end] = dep[t] + 1; q.push(Ed[i].end); if(Ed[i].end == tar) return 1;}
	}
	return 0;
}

int dfs(int x , int v){
	if(x == tar) return v;
	int sum = 0;
	for(int &i = cur[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].f && dep[Ed[i].end] == dep[x] + 1){
			int f = dfs(Ed[i].end , min(Ed[i].f , v - sum)); sum += f; Ed[i].f -= f; Ed[i ^ 1].f += f;
			if(sum == v) break;
		}
	return sum;
}

pii dinic(){
	while(bfs()) dfs(0 , 1e15);
	pii ans;
	for(int i = 1 ; i <= N ; ++i)
		if(L[i] >= 2 && R[i] <= 4 && ~sz[i])
			if(!dep[i]) ans.x += sz[i];
			else if(dep[i + N]) ans.y += sz[i];
	return ans;
}

void hull_div(pii hL , pii hR){
	pii dir = (hL - hR).rot(); init(2 * N + 1);
	for(int i = 1 ; i <= N ; ++i)
		if(L[i] >= 2 && R[i] <= 4 && ~sz[i]){
			addE(0 , i , L[i] >= 3 ? 1e9 : dir.y * sz[i]);
			addE(i , N + i , L[i] == 4 || R[i] == 2 ? 1e9 : (dir.x + dir.y) * sz[i]);
			addE(N + i , tar , R[i] <= 3 ? 1e9 : dir.x * sz[i]);
		}
	for(int i = 1 ; i <= M ; ++i){
		int x = bel[S[i]] , y = bel[T[i]];
		if(x != y && ~sz[x] && ~sz[y] && X[i] == 1){
			addE(x + N , y , 1e9); addE(y + N , x , 1e9);
		}
	}
	pii mid = dinic(); if((hR - mid) % (hL - mid)){hull.push_back(mid); hull_div(hL , mid); hull_div(mid , hR);}
}

void hull_prepare(){
	hull.clear(); hull.push_back(pii(cnt[2] , cnt[4]));
	int num2 = 0 , num4 = 0; for(int i = 1 ; i <= N ; ++i){num2 += L[i] == 2; num4 += R[i] == 4;}
	hull.push_back(pii(num2 , cnt[4])); hull.push_back(pii(cnt[2] , num4)); hull_div(hull[2] , hull[1]);
	memset(V , 0 , sizeof(V)); hull_val.clear();
	for(auto t : hull){
		cnt[2] = t.x; cnt[4] = t.y; cnt[3] = N - t.x - t.y - cnt[1] - cnt[5];
		hull_val.push_back({calc() , cnt[2] , cnt[3] , cnt[4]});
	}
}

signed main(){
	//freopen("qip.in","r",stdin); freopen("qip.out","w",stdout); freopen("qip.log","w",stderr);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for(cin >> C >> C ; C ; --C){
		memset(cnt , 0 , sizeof(cnt)); cin >> K >> N >> M >> Q; for(int i = 1 ; i <= N ; ++i){cin >> L[i] >> R[i]; sz[i] = 0; id[i].clear();}
		for(int i = 1 ; i <= M ; ++i){cin >> S[i] >> T[i] >> X[i]; id[S[i]].push_back(i); id[T[i]].push_back(i);}
		for(int i = 1 ; i <= N ; ++i) for(int j = 1 ; j <= N ; ++j) for(auto p : id[j]){int x = S[p] + T[p] - j; L[x] = max(L[x] , L[j] - X[p]); R[x] = min(R[x] , R[j] + X[p]);}
		for(int i = 1 ; i <= N ; ++i){if(R[i] != 1 && L[i] != K){L[i] = max(L[i] , 2ll); R[i] = min(R[i] , K - 1);} if(L[i] == R[i]) ++cnt[L[i]]; else ++cnt[0];}
		if(K == 5){
			for(int i = 1 ; i <= N ; ++i)
				if(~sz[i]){
					int cnt = 0; queue < int > q; q.push(i); sz[i] = -1;
					while(!q.empty()){
						int t = q.front(); q.pop(); ++cnt; bel[t] = i;
						for(auto p : id[t]){int x = S[p] + T[p] - t; if(X[p] == 0 && ~sz[x]){sz[x] = -1; q.push(x);}}
					}
					sz[i] = cnt;
				}
			hull_prepare();
		}
		while(Q--){
			for(int i = 2 ; i <= K - 1 ; ++i) cin >> V[i];
			switch(K){
			case 3: cout << calc() << '\n'; break;
			case 4:
				static int V2 , V3;
				cnt[2] += cnt[0]; V2 = calc(); cnt[2] -= cnt[0];
				cnt[3] += cnt[0]; V3 = calc(); cnt[3] -= cnt[0];
				cout << max(V2 , V3) << '\n'; break;
			case 5:
				static int mxans; mxans = 0;
				for(auto t : hull_val) mxans = max(mxans , t[0] + t[1] * V[2] + t[2] * V[3] + t[3] * V[4]);
				cout << mxans << '\n';
			}
		}
	}
	return 0;
}

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

詳細信息


Pretests


Final Tests

Test #1:

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

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: 44ms
memory: 3608kb

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: 1ms
memory: 3652kb

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: 80ms
memory: 3964kb

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: 1ms
memory: 3760kb

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

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: 1ms
memory: 3616kb

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: 1ms
memory: 3564kb

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

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

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

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: 15ms
memory: 3684kb

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: 76ms
memory: 3844kb

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: 5ms
memory: 3792kb

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

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: 81ms
memory: 4064kb

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: 40ms
memory: 3748kb

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

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: 129ms
memory: 3668kb

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: 47ms
memory: 3832kb

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: 109ms
memory: 3768kb

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: 363ms
memory: 3864kb

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