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
127
#include "cielib.h"
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define inf 1000000000
#define INF 1000000000000000000LL
#define VI vector<int>
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
using namespace std;

#define D 500

int k, d, r;

int a[D];
int b[D];
int m[D];

int poz[D];

struct comp
{
	bool operator()(const int &p, const int &q)
	{
		return b[p]-a[p]>=b[q]-a[q];
	}
};

set<int, comp> S;

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

	for(int i = 0; i < d; ++i)
	{
		a[i] = 0;
		b[i] = r;
		m[i] = (a[i]+b[i])/2;
		poz[i] = m[i];
		S.insert(i);
	}

	while(!S.empty() && a[*S.begin()]<b[*S.begin()])
	{
		int v = *S.begin();
		S.erase(S.begin());

		if((b[v]-a[v]+1)%2==0)
		{
			if(a[v]==0 && b[v]==r)
			{
				poz[v] = a[v];

				czyCieplo(poz);

				poz[v] = b[v];

				if(czyCieplo(poz))
					++a[v];
				else
					--b[v];

				m[v] = poz[v] = (a[v]+b[v])/2;
			}
			else
			{
				if(b[v]<r)
					++b[v];
				else
					--a[v];

				m[v] = poz[v] = (a[v]+b[v])/2;
			}
		
		}

		poz[v] = a[v];

		czyCieplo(poz);

		poz[v] = b[v];

		if(czyCieplo(poz))
		{
			a[v] = m[v]+1;

			m[v] = poz[v] = (a[v]+b[v])/2;

			S.insert(v);

			continue;
		}

		poz[v] = a[v];

		if(czyCieplo(poz))
		{
			b[v] = m[v]-1;

			m[v] = poz[v] = (a[v]+b[v])/2;

			S.insert(v);

			continue;
		}

		poz[v] = a[v] = b[v] = m[v];

		S.insert(v);

	}

	znalazlem(poz);
}