Educational Codeforces Round 147 (Rated for Div. 2) 1821B - Sort the Subarray Solution



 Problem Link: https://codeforces.com/problemset/problem/1821/B

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 n ; cin >> n ;
  11. vector < int > a(n) , b(n) ;
  12. for ( int i = 0 ; i < n ; i++){
  13. cin >> a[i] ;
  14. }
  15. for ( int i = 0 ; i < n ; i++){
  16. cin >> b[i] ;
  17. }
  18. int left , right ;
  19. for ( int i = 0 ; i < n ; i++){
  20. if(a[i] != b[i]){
  21. left = i ;
  22. right = i ;
  23. }
  24. }
  25. while(left > 0 and b[left-1] <= b[left]){
  26. left-- ;
  27. }
  28. while(right < n - 1 and b[right+1] >= b[right]){
  29. right++ ;
  30. }
  31. cout << (left + 1) <<" "<< (right + 1) << endl ;
  32. }
  33.  
  34. return 0 ;
  35. }

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.