Submission #8363993


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] , arr2[n] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr2[i] ;
	int cnt = 0 ;
	set< pair<int , int> >s ;
	set< pair<int , int> >::iterator it ;
	pair<int , int>p ;
	for(int i = 0 ; i < n ; ++i)
		s.insert({arr[i] , i}) ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(cnt == n-2)
			break ;
		p = *s.begin() ;
		if(p.first > arr2[i])
			return cout<<"No\n" , 0 ;
		it = s.lower_bound({arr2[i]+1 , -1}) ;
		it-- ;
		p = *it ;
		if(p.first != arr[i])
		{
			cnt++ ;
			s.erase({arr[i] , i}) ;
			arr[p.second] = arr[i] ; 
			arr[i] = p.first ; 
			s.erase(p) ;
			s.insert({arr[p.second] , p.second}) ;
			continue ;
		}
		else
			s.erase({arr[i] , i}) ;
	}
	for(int i = 0 ; i < n ; ++i)
	{
		if(arr[i] > arr2[i])
			return cout<<"No\n" , 0 ;
	}
	return cout<<"Yes\n" , 0 ;
}

Submission Info

Submission Time
Task C - Swaps
User MohamedAhmed04
Language C++14 (GCC 5.4.1)
Score 600
Code Size 995 Byte
Status
Exec Time 123 ms
Memory 7424 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample01.txt, sample02.txt, sample03.txt
All 600 / 600 sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt 119 ms 5376 KB
in02.txt 112 ms 5248 KB
in03.txt 110 ms 5248 KB
in04.txt 119 ms 5504 KB
in05.txt 122 ms 5504 KB
in06.txt 108 ms 5504 KB
in07.txt 114 ms 5760 KB
in08.txt 107 ms 5504 KB
in09.txt 104 ms 7424 KB
in10.txt 106 ms 5504 KB
in11.txt 113 ms 5248 KB
in12.txt 110 ms 5248 KB
in13.txt 116 ms 5248 KB
in14.txt 121 ms 5632 KB
in15.txt 110 ms 5248 KB
in16.txt 118 ms 5376 KB
in17.txt 112 ms 5248 KB
in18.txt 119 ms 5504 KB
in19.txt 114 ms 5376 KB
in20.txt 123 ms 5632 KB
in21.txt 111 ms 5504 KB
in22.txt 106 ms 5632 KB
in23.txt 106 ms 5504 KB
in24.txt 98 ms 5248 KB
in25.txt 102 ms 5376 KB
in26.txt 28 ms 1792 KB
in27.txt 30 ms 1792 KB
in28.txt 39 ms 2432 KB
in29.txt 2 ms 384 KB
in30.txt 5 ms 512 KB
in31.txt 61 ms 3328 KB
in32.txt 29 ms 1920 KB
in33.txt 41 ms 2560 KB
sample01.txt 1 ms 256 KB
sample02.txt 1 ms 256 KB
sample03.txt 1 ms 256 KB