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

using namespace std;

int main()
{
	if(MyNodeId() != 0)
		return 0;
	
  int n = PipeHeight();
  int m = NumberOfDiscs();
  vector<long long> w(n, 0);

  w[1] = HoleDiameter(1);
  for (int i = 2; i <= n; i++) {
    w[i] = HoleDiameter(i);
    w[i] = min(w[i], w[i-1]);
  }

  int d = n;
  for (int i = 1; i <= m; i++) {
    long long x;
    x = DiscDiameter(i);
    while (d>0 && w[d-1]<x) d--;
    d--;
  }

  printf("%d\n", max(0, d + 1));
  return 0;
}