Codeforces Round 970 (Div. 3) 2008C. Longest Good Array Solution
Problem Link https://codeforces.com/contest/2008/problem/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int a , b ; cin >> a >> b ;
- long long l , r ;
- l = 1 , r = 1e5 ;
- while(l <= r ){
- long long mid = ( l + r )/ 2 ;
- long long x = (mid * ( mid + 1))/ 2 ;
- if( a + x <= b ){
- l = mid + 1 ;
- }
- else{
- r = mid - 1 ;
- }
- }
- cout << l << '\n';
- }
- return 0 ;
- }
No comments