[Codeforces] Round #404 (Div. 2) C. Anton and Fairy Tale

Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale

  • Time :
  • Space :
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
def func(n):
return n * (n + 1) // 2;

def helper(n, m, mid):
k = n + (mid - m) * m;
eat = func(mid) - func(m - 1);
return k - eat;

def solve(n, m):
if n <= m:
return n;
l = m
r = 10**18
res = 10**18;
while l <= r :
mid = l + (r - l) // 2;
s = helper(n,m,mid);
if s <= 0:
res = min(res, mid);
r = mid - 1;
else:
l = mid + 1;

return res;

n, m = map(int,input().split())

print(solve(n,m))
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/12/05/PS/Codeforces/div2-404-c/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.