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
#include <cstdio>
#include <algorithm>
#include <climits>
#include "krazki.h"
#include "message.h"

#define MAX_N 30000000

using namespace std;

long long tube[MAX_N + 2];

int n, m;

void read() {
    n = PipeHeight();
    m = NumberOfDiscs();

    tube[0] = LLONG_MAX;
    for (int i = 1; i <= n; i++) {
        long long diam = HoleDiameter(i);
        tube[i] = min(tube[i-1], diam);
    }
    tube[n + 1] = 0;
}

int compute() {
    int pos = n + 1;
    for (int i = 1; i <= m; i++) {
        long long disc = DiscDiameter(i);
        if (pos > 0) {
            pos--;
        }
        while (tube[pos] < disc) {
            pos--;
        }
    }

    return pos;
}

int main() {

    if (MyNodeId() == 0) {
        read();
        printf("%d\n", compute());
    }

    return 0;
}