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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "cielib.h"
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>

using namespace std;


struct Node
{
	int number;
	int min;
	int max;
};
struct NodeCompare
{
	bool operator() (const Node a, const Node b) const {
		return (a.max - a.min) > (b.max - b.min);
	}
};

int position[500];
int firstNode[500];
int secondNode[500];
int thirdNode[500];
multiset<Node, NodeCompare> minMax;

int main() {
	int d = podajD();
	int k = podajK();
	int r = podajR();

	Node node;
	for (int i = 0; i < d; i++)
	{
		position[i] = 0;
		node.number = i;
		node.min = 0;
		node.max = r;
		minMax.insert(node);
	}

	int valuesSet = 0;
	for (auto it = minMax.begin(); it != minMax.end(); )
	{
		int middle = (it->min + it->max) >> 1;
		if (it->max - it->min == 1)
		{
			it++;
			continue;
		}
		int maxDiff = 0;
		for (auto it2 = minMax.begin(); it2 != minMax.end(); ++it2)
		{
			position[it2->number] = ((it2->min + it2->max) >> 1) + 1;
			if (it2->max - it2->min > maxDiff && it->number != it2->number)
				maxDiff = it2->max - it2->min;
		}
		position[it->number] = it->min;
		czyCieplo(position);
		position[it->number] = it->max;
		Node node = *it;
		if (czyCieplo(position))
		{
			node.min = middle;
		}
		else
		{
			node.max = middle;
		}
		minMax.erase(it);
		minMax.insert(node);
		it = minMax.begin();

		if (node.max - node.min == 1) valuesSet++;
	}

	for (auto it = minMax.begin(); it != minMax.end(); )
	{
		if (it->max == it->min)
		{
			++it;
			continue;
		}
		for (auto it2 = minMax.begin(); it2 != minMax.end(); ++it2)
		{
			position[it2->number] = (it2->min + it2->max) >> 1;
		}
		if (it->max < r)
		{
			position[it->number] = it->max + 1;
			czyCieplo(position);
			position[it->number] = it->min;
			Node node = *it;
			if (czyCieplo(position))
				node.max = it->min;
			else
				node.min = it->max;
			minMax.erase(it);
			minMax.insert(node);
		}
		else
		{
			position[it->number] = it->min - 1;
			czyCieplo(position);
			position[it->number] = it->max;
			Node node = *it;
			if (czyCieplo(position))
				node.min = it->max;
			else
				node.max = it->min;
			minMax.erase(it);
			minMax.insert(node);
		}
		it = minMax.begin();
	}

	for (auto it = minMax.begin(); it != minMax.end(); ++it)
	{
		position[it->number] = it->min;
	}

	znalazlem(position);
	return 0;
}