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
52
53
#include <cstdlib>
#include <iostream>
#include "krazki.h"
#include "message.h"
using namespace std;

long long int minima[30000007];

int main() {
    // Tylko zerowy komputer coś liczy.
    if (MyNodeId() != 0) {
    return EXIT_SUCCESS;
    }
    int n = PipeHeight(), m = NumberOfDiscs();
    int depth;
    if(n >= 30000007)
        depth = 0;
    else
    {
        for(int i = 1; i <= n; ++i)
        {
            if(i == 1)
                minima[i] = HoleDiameter(i);
            else
                minima[i] = min(minima[i - 1], HoleDiameter(i));
        }
        int wsk = n;
        for(int i = 1; i <= m && wsk > 0; ++i)
        {
            long long int x = DiscDiameter(i);
            if(minima[wsk] >= x && i > 1)
                --wsk;
            while(wsk > 0 && minima[wsk] < x)
                --wsk;
        }
        depth = max(0, wsk);
    }
    /*
    int depth;
    long long int max_disc_diameter = 0;
    for (int i = 1; i <= NumberOfDiscs(); i++) {
    max_disc_diameter = std::max(max_disc_diameter, DiscDiameter(i));
    }
    if (HoleDiameter(PipeHeight()) < max_disc_diameter) {
    depth = 0;
    } else {
    depth = std::max(0, PipeHeight() - NumberOfDiscs() + 1);
    }
    std::cout << depth << std::endl;
    */
    cout << depth << endl;
    return EXIT_SUCCESS;
}