forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
61 lines (53 loc) · 1.62 KB
/
B.cpp
File metadata and controls
61 lines (53 loc) · 1.62 KB
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
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define DEBUG(x) { cout << #x << " = "; cout << (x) << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
using namespace std;
int a[2222][2222];
int main()
{
ios::sync_with_stdio(0);
freopen("bandits.in", "r", stdin);
freopen("bandits.out", "w", stdout);
int n, m;
while (cin >> n >> m) {
assert(1 <= n && n <= 2000);
assert(1 <= m && m <= 2000);
memset(a, 0, sizeof a);
a[1][1] = m;
for (int i = 2; i <= n; i++)
{
vector < pair<int,int> > b;
for (int j = 1; j < i; j++)
b.emplace_back(a[i - 1][j], j);
sort(b.begin(), b.end());
int need = i / 2, sum = 0;
for (int j = 0; j < need; j++)
sum += b[j].first + 1;
if (sum > m)
{
a[i][i] = -1;
for (int j = 1; j < i; j++)
a[i][j] = a[i - 1][j];
}
else
{
a[i][i] = m - sum;
bool ok = true;
if (need < i && b[need].first == b[need-1].first) {
ok = false;
}
for (int j = 0; j < need; j++) {
if (ok || b[j].first + 1 <= b[need].first)
a[i][b[j].second] = b[j].first + 1;
}
}
// PR(a[i], i);
}
cout << a[n][n] << endl;
}
}