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
#include <iostream>
#include <vector>
#include "krazki.h"
#include "message.h"

using namespace std;

typedef long long ll;

int main()
{
    if (MyNodeId() != 0) return EXIT_SUCCESS;
	int n = PipeHeight(), m = NumberOfDiscs();
	vector<ll> a(n);
	ll d;
	for (int i = 0; i < n; ++i)
	{
		d = HoleDiameter(i + 1);
		if (i == 0) a[i] = d;
		else a[i] = (a[i - 1] < d) ? a[i - 1] : d;
	}
	int poz = n;
	int i = 0;
	while (m > 0)
	{
		d = DiscDiameter(i + 1);
		if (poz != -1)
		{
			--poz;
			while (poz >= 0 && d > a[poz]) --poz;
		}
		else
        {
            cout << poz + 1;
            return EXIT_SUCCESS;
        }
		--m;
		++i;
	}
	cout << poz + 1;
	return EXIT_SUCCESS;
}