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
48
49
#include <iostream>
#include <algorithm>

#include "krazki.h"
#include "message.h"

int main()
{
	if (MyNodeId() != 0)
	{
		return 0;
	}

	int n = PipeHeight();
	int m = NumberOfDiscs();

	if (m > n)
	{
		std::cout << "0\n";

		return 0;
	}

	long long int *mins = new long long int[n + 1];

	mins[1] = HoleDiameter(1);
	for (int i = 2; i <= n; ++i)
	{
		mins[i] = std::min(mins[i - 1], HoleDiameter(i));
	}

	int prev = n + 1;

	for (int j = 1; j <= m; ++j)
	{
		int a = prev - 1;
		while (a > 0 && mins[a] < DiscDiameter(j)) --a;
		prev = a;

		if (prev == 0)
		{
			break;
		}
	}

	std::cout << prev << "\n";

	return 0;
}