0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:11:59 +00:00
Baoshuo Ren 2021-11-22 19:38:28 +08:00 committed by Baoshuo Ren
parent 53d51ed170
commit d9ff28991c
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

49
CodeForces/1612/C/C.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <bits/stdc++.h>
using namespace std;
int t, k;
long long x, ans;
inline long long calc(long long d) {
return (d + 1) * d / 2;
}
inline long long calc2(long long d) {
return (k * 2 - d + 1) * d / 2;
}
int main() {
cin >> t;
while (t--) {
cin >> k >> x;
long long l = 0, r = k;
while (l < r) {
int mid = l + r + 1 >> 1;
if (calc(mid) <= x) {
l = mid;
} else {
r = mid - 1;
}
}
if (r < k) {
ans = r + (calc(r) < x);
cout << min(ans, k * 2ll - 1) << endl;
continue;
}
x -= (k - 1ll) * k / 2ll;
l = 0;
r = k;
while (l < r) {
int mid = l + r + 1 >> 1;
if (calc2(mid) <= x) {
l = mid;
} else {
r = mid - 1;
}
}
ans = (r + k - 1 + (calc2(r) < x));
cout << min(ans, k * 2ll - 1) << endl;
}
return 0;
}