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

using namespace std;

const int N = 30000000;

long long mini[N];

int main() {
    ios_base::sync_with_stdio(0);

    int n, m;

    if (MyNodeId() == 0) {

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

        /* ALGORYTM */
        mini[1] = HoleDiameter(1);

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

        int last = n + 1;
        int a;

        for (int i = 1; i <= m; i++) {
            a = last - 1;

            while (a > 0 && mini[a] < DiscDiameter(i)) {
                a--;
            }

            last = a;

            if (last == 0) {
                cout << 0;
                return 0;
            }
        }

        cout << last;
    }


    return 0;
}