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
#include <bits/stdc++.h>
#include "cielib.h"
using namespace std;
#define M 500
//#define test

#ifdef test
#define DD 5
#define RR 1000000000
int Krotka[DD]={0,0,0,0,0};
int ym=-1;
int podajD() {return DD;}
int podajR() {return RR;}
int K;
int czyCieplo(int p[]) {
	K++;
	int m=0;
	for (int i=0;i<DD;i++)
		m = max(abs(Krotka[i]-p[i]),m);
	bool cieplo = m<ym;
	ym=m;
	return cieplo;
}
void znalazlem(int p[]) {
	cout << K << endl;
	for (int i=0;i<DD;i++)
		cout << p[i] << " ";
}
#endif



priority_queue<pair<int,int> > Q;
int a[M],b[M],p[M];
int D,R;

void init1() {
	D=podajD();
	R=podajR();
	for (int i=0;i<D;i++) {
		a[i]=0;
		b[i]=R;
		p[i]=(a[i]+b[i])/2;
		Q.push(make_pair(b[i]-a[i],i));
	}
}

void go() {
	while (Q.top().first>0)	{
		int d=Q.top().second; Q.pop();
		int g = (b[d]-a[d]+1)/2;
		int pair = (b[d]-a[d])%2 == 0;
		//printf("d=%d a=%d b=%d g=%d pair=%d\n",d,a[d],b[d],g,pair);
		p[d]=a[d];
		czyCieplo(p);
		p[d]=b[d];
		if (czyCieplo(p)) {
			a[d] += g+pair;
			if (b[d]-a[d]==1) a[d]--;
			//cout << "prawo\n";
		} else {
			p[d]=a[d];
			if (czyCieplo(p)) {
				b[d] -= g+pair;
				if (b[d]-a[d]==1) b[d]++;
				//cout << "lewo\n";
			} else {
				int c=a[d];
				a[d]=b[d]-g;
				b[d]=c+g;
				if (b[d]-a[d]==1) b[d]++;
				//cout << "srodek\n";
			}
		}
		Q.push(make_pair(b[d]-a[d],d));
		p[d]=(a[d]+b[d])/2;
		//printf("d=%d a=%d b=%d \n",d,a[d],b[d]);
	}
	znalazlem(p);
}

int main() {
	init1();
	go();
	return 0;
}