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
#include <iostream>
#include <algorithm>
#include "message.h"
#include "krazki.h"
using namespace std;
 
long long a[30000000];

int main()
{
    if(MyNodeId() != 0) {
        return 0;
    }
    long long r = PipeHeight();
    long long k = NumberOfDiscs();
    
    if(k > r) {
        cout << "0" << endl;
        return 0;
    }
    a[r] = 1000000000000000000L;
    
    for(long long i = r - 1; i >= 0; i --) { 
        a[i] = min(HoleDiameter(i + 1), a[i+1]);
    }
    
    long long j = 0;
    long long x;
    for(long long i = 0; i < k; i ++) {
        x = DiscDiameter(i + 1);
        while(j < r && a[j] < x) {
            j ++;
        }
        if(j == r) {
            cout << "0" << endl;
            return 0;
        } else {
            j++;
        }
    }
    cout << r - j + 1 << endl;
    return 0;
}