1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
#include "krazki.h"
#include "message.h"
using namespace std;
int main()
{
	if(MyNodeId() == 0)
	{
	int depth, query;
	depth = PipeHeight();
	query = NumberOfDiscs();

	int holes[depth];
	int pegs [query];
	int minima[depth];
	
	minima[0] = holes[0];
	
	for(int i = 0 ; i < depth; i++)
		holes[i] = HoleDiameter(i+1);
		
	for(int i = 0 ; i < query; i++)
		pegs[i] = DiscDiameter(i+1);

	for(int i = 1; i < depth; i++)
		minima[i] = min(minima[i-1], holes[i]);
		
	int pop = depth;
		
	for(int i = 0 ; i < query; i++)
	{
		int a = pop-1;
		while((a > 0) && (minima[a] < pegs[i]))
		{
			a=a-1;	
			if(a==0){
				printf("0");
				return 0;
			}
		}	
			pop = a;
	}
	printf("%d", pop+1);
	}
	else
	return 0;
}