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
// #include <iostream>

#include "cielib.h"

// using namespace std;

int FloorMid(const int lower, const int upper) {
  return (lower + upper) / 2;
}

int CeilMid(const int lower, const int upper) {
  return (lower + upper + 1) / 2;
}

int main() {
  const int d = podajD();
  const int r = podajR();

  int t[d], lower[d], upper[d];

  for(int i = 0; i < d; ++i) {
    lower[i] = 0;
    upper[i] = r;
  }

  while (true) {
    int best = 0;
    for (int i = 1; i < d; ++i) {
      if (upper[i] - lower[i] > upper[best] - lower[best]) best = i;
    }
    if (upper[best] == lower[best]) break;
    if (upper[best] - lower[best] == 1) {
      if (lower[best] == 0) ++upper[best]; else --lower[best];
    }
    // cerr << best << ' ' << lower[best] << ' ' << upper[best] << endl;
    for (int i = 0; i < d; ++i) t[i] = FloorMid(lower[i], upper[i]);
    t[best] = lower[best];
    czyCieplo(t);
    t[best] = upper[best];
    if (czyCieplo(t)) {
      // cerr << "upper is better" << endl;
      lower[best] = FloorMid(lower[best], upper[best]) + 1;
    } else {
      t[best] = lower[best];
      if (czyCieplo(t)) {
        // cerr << "lower is better" << endl;
        upper[best] = CeilMid(lower[best], upper[best]) - 1;
      } else {
        // cerr << "all the same" << endl;
        const int lower_new = FloorMid(lower[best], upper[best]);
        const int upper_new = CeilMid(lower[best], upper[best]);
        lower[best] = lower_new;
        upper[best] = upper_new;
      }
    }
  }
  znalazlem(upper);
  return 0;
}