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
76
77
78
79
80
81
82
83
84
85
86
87
#include "cielib.h"
#include <bits/stdc++.h>
using namespace std;

int main() 
{
	int d = podajD();
	int prom = podajR();
	int t[d], l[d], r[d], ans[d];
	for(int i = 0; i < d; ++i) 
	{
		l[i] = 0;
		r[i] = prom;
		t[i] = 0;
		ans[i] = 0;
	}

	for (int ii = 1; ii <= 40; ++ ii)
	{
		for (int i = 0; i < d; ++ i)
			t[i] = (l[i] + r[i]) / 2;
	
		for (int i = 0; i < d; ++ i)
		{
			int m = (l[i] + r[i]) / 2;
			
			t[i] = r[i]; 
			czyCieplo(t);
			t[i] = l[i]; 
			if (czyCieplo(t))
			{
				if ((l[i]+r[i])%2==1)
					r[i] = m+1;
				else
					r[i] = m;
			}
			else
				l[i] = m;
			
			t[i] = m;
		}
	}
	
	for( int i = 0; i < d; ++ i)
		t[i] = min(r[i], prom-1);
		
	czyCieplo(l);
	if (czyCieplo(t))
	{
		znalazlem(t);
		return 0;
	}
	czyCieplo(r);
	if (czyCieplo(t))
	{
		znalazlem(t);
		return 0;
	}
	
	for (int i = 0; i < d; ++ i)
	{
		int stare = t[i];
		if (r[i] == prom)	
			t[i] = l[i]-1;
		else
			t[i] = r[i]+1;
	
		czyCieplo(t);
		t[i] = stare;
		if (czyCieplo(t))
		{	
			if (r[i] == prom)
				ans[i] = r[i];
			else
				ans[i] = l[i];
		}
		else
		{
			if (r[i] == prom)
				ans[i] = l[i];
			else
				ans[i] = r[i];
		}	
	}

	znalazlem(ans);	
}