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

long long rurka[5000001];
long long krazki[5000001];

int main(){
    int n = PipeHeight(), m = NumberOfDiscs();
    if(m > n && MyNodeId() == 0) cout << "0\n";
    else if(MyNodeId() == 0 && n<=5000000 && m<=5000000){
        for(int i=1; i<=n; i++){
            rurka[i]=HoleDiameter(i);
        }
        for(int i=2; i<=n; i++){
            rurka[i]=min(rurka[i], rurka[i-1]);
        }
        for(int i=1; i<=m; i++){
            krazki[i]=DiscDiameter(i);
        }
        int j=1, w=1;
        for(int i=n; i>=1; i--){
            if(krazki[j] <= rurka[i]){
                if(++j > m){
                    w=0;
                    cout << i << "\n";
                    break;
                }
            }
        }
        if(w) cout << "0\n";
    }
    else if(MyNodeId() == 0) cout << "0\n";
}