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++:
- /// 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 n ; cin >> n ;
- vector < int > a(n) , b(n) ;
- for ( int i = 0 ; i < n ; i++){
- cin >> a[i] ;
- }
- for ( int i = 0 ; i < n ; i++){
- cin >> b[i] ;
- }
- int left , right ;
- for ( int i = 0 ; i < n ; i++){
- if(a[i] != b[i]){
- left = i ;
- right = i ;
- }
- }
- while(left > 0 and b[left-1] <= b[left]){
- left-- ;
- }
- while(right < n - 1 and b[right+1] >= b[right]){
- right++ ;
- }
- cout << (left + 1) <<" "<< (right + 1) << endl ;
- }
- return 0 ;
- }
No comments