Codeforces Round 633 (Div. 2) 1339C - Powered Addition / Codeforces Round 633 (Div. 1) 1338A. Powered Addition Solution


 

Problem Link  :  https://codeforces.com/contest/1338/problem/A , https://codeforces.com/contest/1339/problem/C

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int t ;
  13. cin >> t ;
  14. while ( t-- ) {
  15. int n ;
  16. cin >> n ;
  17. int a[n+1] ;
  18. for ( int i = 0 ; i < n ; i++ ){
  19. cin >> a[i] ;
  20. }
  21. int mx = 0 ;
  22. for ( int i = 1 ; i < n ; i++ ) {
  23. if ( a[i - 1] > a[i] ) {
  24. mx = max ( mx , a[i - 1] - a[i] ) ;
  25. a[i] = a[i - 1] ;
  26. }
  27. }
  28. cout << (int )ceil(log2(mx+1)) << endl;
  29. }
  30. return 0 ;
  31. }

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 ...

Powered by Blogger.