Codeforces Round 970 (Div. 3) 2008C. Longest Good Array Solution

 


Problem Link   https://codeforces.com/contest/2008/problem/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. int a , b ; cin >> a >> b ;
  11. long long l , r ;
  12. l = 1 , r = 1e5 ;
  13. while(l <= r ){
  14. long long mid = ( l + r )/ 2 ;
  15. long long x = (mid * ( mid + 1))/ 2 ;
  16. if( a + x <= b ){
  17. l = mid + 1 ;
  18. }
  19. else{
  20. r = mid - 1 ;
  21. }
  22. }
  23. cout << l << '\n';
  24. }
  25. return 0 ;
  26. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.