-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode760B.cpp
More file actions
49 lines (39 loc) · 862 Bytes
/
Copy pathcode760B.cpp
File metadata and controls
49 lines (39 loc) · 862 Bytes
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
/**
* Contest : Codeforces Round 393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)
* Problem : B - Frodo and pillows
* Link : https://codeforces.com/problemset/problem/760/B
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
ll n, m, k;
ll f(ll len, ll x) {
ll first = max(1LL, x-len+1), last = x, cnt = 0;
if (len > x)
cnt += len-x;
cnt += (first + last) * (last - first + 1)/2;
return cnt;
}
bool valid(ll x) {
ll left = k-1, right = n-k;
return x + f(left,x-1) + f(right, x-1) <= m;
}
ll bs() {
ll l = 1, r = m;
while (l <= r) {
ll mid = l + (r-l)/2;
if (valid(mid))
l = mid+1;
else
r = mid-1;
}
return r;
}
int main() {
fastio
cin >> n >> m >> k;
cout << bs() << endl;
return 0;
}