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
#include <iostream>
#include "cielib.h"

using namespace std;

const int MAXD = 501;

int P[MAXD];
pair<int, int> D[MAXD];

void solve1() {
	while(D[0].first < D[0].second) {
		int m = (D[0].first + D[0].second + 1) / 2;
		int prev = P[0];
		P[0] = D[0].second;
		if(czyCieplo(P)) {
			D[0].first = m;
			P[0] = m;
		} else {
			P[0] = D[0].first;
			if(D[0].first + 1 == D[0].second) --m;
			D[0].second = m;	
		}
		czyCieplo(P);
	}
}

void find(int d, int &idx) {
	for(int i=0; i<d; ++i) {
		if(D[i].first < D[i].second) {
			++P[i];
			if(czyCieplo(P)) {
				idx = i;
				--P[i];
				czyCieplo(P);
				return;
			} else {
				--P[i];
				czyCieplo(P);
			}
		}
	}
	
	idx=0;
	while(D[idx].first >= D[idx].second) ++idx;
	return;
}

void solve(int d) {
	czyCieplo(P);
	
	if(d==1) {
		solve1();
		return;
	}
	
	bool b = true;
	while(b) {
		int idx=-1, dx=0;
		
		find(d, idx);
		
		
		int m = (D[idx].first + D[idx].second + 1) / 2;
		int prev = P[idx];
		P[idx] = D[idx].second;
		if(czyCieplo(P)) {
			D[idx].first = m;
			P[idx] = m;
		} else {
			P[idx] = D[idx].first;
			if(D[idx].first + 1 == D[idx].second) --m;
			D[idx].second = m;	
		}
		czyCieplo(P);
		
		
		b = false;
		for(int i=0; i<d; ++i)
			if(D[i].first < D[i].second) b = true;
	}	
	
}

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(0);

	int d = podajD();
	int r = podajR();
	
	for(int i=0; i<d; ++i) {
		D[i].first = 0;
		D[i].second = r;
		P[i] = 0;
	}
	
	solve(d);
	
	znalazlem(P);
	
	return 0;
}