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
#include <bits/stdc++.h>
#include <krazki.h>
#include <message.h>

using namespace std;

const int INF = 1e18 + 7;
vector<long long> v;
vector<long long> mn;
long long x;
int n, m, h;

int main()
{
    if(MyNodeId() != 0) return 0;
    n = PipeHeight();
    m = NumberOfDiscs();
    cin >> n >> m;
    v.resize(n + 1);
    mn.resize(n + 1, INF);
    for(int i = 1; i <= n; i++)
        v[i] = HoleDiameter(i);
    mn[1] = v[1];
    for(int i = 2; i <= n; i++)
    {
        mn[i] = mn[i - 1];
        if(v[i] < mn[i - 1]) mn[i] = v[i];
    }
    h = n + 1;
    bool ok;
    for(int i = 1; i <= m; i++)
    {
        x = DiscDiameter(i);
        while(h > 1)
        {
            if(x <= mn[h - 1])
            {
                h--;
                break;
            }
            else h--;
        }
    }
    int res;
    if(ok == 1) res = 0;
    else res = h;
    printf("%d\n", res);
    return 0;
}