-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathneps3268.cpp
More file actions
45 lines (35 loc) · 744 Bytes
/
Copy pathneps3268.cpp
File metadata and controls
45 lines (35 loc) · 744 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
/*
* Contest : OBI 2025 - Fase 2
* Problem : Um Desafio Muito Distinto
* Link : https://neps.academy/br/exercise/3268
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
bool isValid(ll a, ll n, ll target) {
n--;
return n * (2 * a + n - 1) / 2 < target; //
}
ll bs(ll target, ll a, ll b) {
ll l = 1, r = b - a + 1, m, ans = -1;
while (l <= r) {
m = l + (r - l) / 2;
if (isValid(a, m, target)) {
l = m + 1;
ans = m;
} else
r = m - 1;
}
return ans;
}
int main() {
fastio
int tc; cin >> tc;
while (tc--) {
ll target, a, b;
cin >> target >> a >> b;
cout << bs(target, a, b) << '\n';
}
return 0;
}