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 AC
Exec Time 123 ms
Memory 7424 KB

Judge Result

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