-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatBan.cpp
More file actions
56 lines (52 loc) · 1.25 KB
/
Copy pathChatBan.cpp
File metadata and controls
56 lines (52 loc) · 1.25 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
// Codeforces Problem: C - Chat Ban
// Link: https://codeforces.com/contest/1612/problem/C
// Status: Accepted Language: C++
#include<iostream>
// #include<bits/stdc++.h>
// #include<set>
// #include<vector>
// #include<map>
// #include<algorithm>
using namespace std;
#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
ll sum (ll num) {
return num * (num + 1) / 2;
}
int main () {
int t;
cin>>t;
while (t--) {
ll k, x;
cin>>k>>x;
ll l = 1, tot = 2 * k - 1, r = 2 * k - 1;
bool big = false;
while (l <= r) {
ll mid = (l + r) >> 1;
if (mid >= k) {
if (sum (k) + sum (k - 1) - sum (2 * k - 1 - mid) >= x) {
big = true;
} else {
big = false;
}
} else {
if (sum (mid) >= x) {
big = true;
} else {
big = false;
}
}
if (big) {
tot = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout<<tot<<nl;
}
return 0;
}