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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstdlib>
#include <iostream>
#include <vector>

#include "krazki.h"
//#include "krazki.cpp"
#include "message.h"

using namespace std;

int n;
int m;
vector<long long> vec;
vector<long long> tests;

int last;

int findMin(int nr)
{
  long long val = tests[nr-1];
  int res = 0;
  for (int i = 1; i <= last; i++)
  {
    if (val > vec[i-1])
    {
      break;
    }
    else
    {
      res++;
    }
  }
  return res;
}

int main() {
  // Tylko zerowy komputer coś liczy.
  if (MyNodeId() != 0) {
    return EXIT_SUCCESS;
  }

  n = PipeHeight();
  m = NumberOfDiscs();

  long long d;
  for (int i = 1; i <= n; i++)
  {
    d = HoleDiameter(i);
    vec.push_back(d);
  }

  for (int i = 1; i <= m; i++)
  {
    d = DiscDiameter(i);
    tests.push_back(d);
  }

  last = n;

  for (int i = 1; i <= m; i++)
  {
    last = findMin(i);
    if (i < m)
    {
      last--;
    }
    if (last == 0)
    {
      break;
    }
  }

  std::cout << last << std::endl;
  return EXIT_SUCCESS;
}