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

using namespace std;

deque< pair<long long, long long> > kolej;
long long ID, nrOfNodes, n, k, hole_diam, level;
long long akt_krazek = 1, akt_diam, ret;
int main() {
    ID = MyNodeId();
    nrOfNodes = NumberOfNodes();
    n = PipeHeight();
    k = NumberOfDiscs();
        
 /*   fromD = (nrOfNodes - id - 1)*(k/nrOfNodes) + 1;

    if (id == 0)
        uptoD = k;
    else
        uptoD = (nrOfNodes - id)*(k/nrOfNodes); */

if (ID == 0) {
	akt_diam = DiscDiameter(akt_krazek);

    for (long long i = 1; i <= n + 1; i++) {
		if (i <= n)
			hole_diam = HoleDiameter(i);
		else
			hole_diam = 0;
        if (kolej.empty())
            kolej.push_front({hole_diam, i});
        else {
            if (hole_diam < kolej.front().first) {
                kolej.push_front({hole_diam, i});
            }
        }
        if (akt_diam > hole_diam) {
			kolej.pop_front();
			kolej.push_front({0, i-1});
			ret = i - 1;
			akt_krazek++;
			break;
		}
    }
    
    while (akt_krazek <= k && ret > 0) {
		akt_diam = DiscDiameter(akt_krazek);
		while(!kolej.empty()) {
			if (akt_diam > kolej.front().first) {
				ret = kolej.front().second - 1;
				kolej.pop_front();
			} else {
				break;
			}
		}
		kolej.push_front({0, ret});
		akt_krazek++;
	}
	
	printf("%lld\n", ret); 
}
    return 0;
}