Problem:


Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes



Sample input:
3
1 3 2
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

from bisect import bisect_left

#インデックス付きソート
#(index,value)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

A2 = sorted(A)
B2 = sorted(B)

for i in range(N):
    if A2[i]>B2[i]:
        print('No')
        exit()

for i in range(N-1):
    if B2[i]>=A2[i+1]:
        print('Yes')
        exit()

A3 = index_sort(A)
B3 = index_sort(B)

Ac = A[:]
for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    p1 = bisect_left(A2,Ac[bindex])
    A3[p1][0] = i
    A3[i][0] = p1


for i in range(N):
    if A[i]>B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

num = 0
for i in range(n):
    if a[i] > b[i]:
        num += 1
if num >= n-2:
    print('No')
    exit()

lst_original = []
for i in range(n):
    lst_original.append(a[i]-b[i])

a.sort()
b.sort()

lst_ato = []
for i in range(n):
    lst_ato.append(a[i]-b[i])
    if a[i] > b[i]:
        print('No')
        exit()

lst_original.sort()
lst_ato.sort()

num_dif = 0
for i in range(n):
    if lst_ato[i] != lst_original[i]:
        num_dif += 1

if num_dif >= n:
    print('No')
    exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        exit()

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

A = [-1] * N
B = [-1] * N

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    A[i] = k
    B[j] = k

aToI = {a : i for i, a in enumerate(A)}

cnt = 0
visited = [False] * N
for i, a in enumerate(A):
    if visited[i]:
        continue

    leng = 0
    now = i
    while True:
        visited[now] = True
        now = aToI[B[i]]
        if visited[now]:
            break
        leng += 1
        visited[now] = True
    cnt += leng

if cnt <= N - 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import bisect
# from operator import itemgetter
input = sys.stdin.readline

_n = int(input())
_alist = list(map(int, input().split()))
_blist = list(map(int, input().split()))


def chker(A, B):
    for a, b in zip(A, B):
        if a > b:
            print('No')
            return

    print('Yes')


def loopchk(n, A, B):
    ba = list(zip(B, A))
    ba.sort()
    ba = np.array([[b, a] for b, a in ba if a != b])
    B, A = ba[:, 0], ba[:, 1]
    limit = n - 2
    lng = len(B)
    for i in range(lng):
        if A[i] < B[i]:
            continue

        index = bisect.bisect_left(B, A[i])
        for j in range(index, lng):
            if A[j] <= B[i]:
                A[i], A[j] = A[j], A[i]
                limit -= 1
                if limit == 0:
                    chker(A, B)
                    sys.exit()
                break

    chker(A, B)


loopchk(_n, _alist, _blist)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list( map(int, input().split()))
b = list( map(int, input().split()))

cba_list = [[0, 0,0] for _ in range(n)]
for i in range(n):
    cba_list[i]= [b[i]-a[i], b[i], a[i] ]

cba_list.sort()
cba_list_reverse = sorted(cba_list, reverse = True)

count = 0
for i in range(n):
    if cba_list[i][0] < 0:
        flg = 1
        for j in range(n):
            if cba_list_reverse[j][1] >= cba_list[i][2] and cba_list_reverse[j][2] <= cba_list[i][1]:
                tempa = cba_list[i][2]
                tempb = cba_list[i][1]
                cba_list[i][2] = cba_list_reverse[j][2]
                cba_list[i][1] = cba_list_reverse[j][1]

                cba_list_reverse[j][2] = tempa
                cba_list_reverse[j][1] = tempb
                flg = 0
                count += 1
                break
        if flg == 1 or count > n-2:
            print('No')
            exit()


print('Yes')

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right, bisect_left
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
sortedAs = sorted(As)
sortedBs = sorted(Bs)
arr = []
for i in range(N):
    if sortedAs[i] > sortedBs[i]:
        print('No')
        exit()
    if i >= 1 and sortedAs[i] > sortedBs[i-1]:
        arr.append(i)
for a, b in zip(As, Bs):
    idxa = bisect_right(sortedAs, a)
    idxb = bisect_left(sortedBs, b)
    if bisect_right(arr, idxa) == bisect_right(arr, idxb):
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = 0
b = 0
AA = sorted(A)
BB = sorted(B)
while a <= N-1:
  b = 0
  A[A.index(AA[N-a-1])],A[B.index(BB[N-a-1])] = A[B.index(BB[N-a-1])],A[A.index(AA[N-a-1])]
  a += 1
  for x in range(N):
    if A[x] > B[x]:
      b = 2
  if b == 0:
    break
if a == N-1:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break

ans=0
if N%2==0:
    ans=N//2
else:
    ans=N//2+1
if ans>N-2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# C - Swaps
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
count2 = 0
count3 = 0

for i in range(len(A)):
    if A[i] > B[i]:
        count += 1
        count2 += 1
    elif A[i] < B[i]:
        count += -1
    else:
        pass

A.sort(reverse=True)
B.sort(reverse=True)
# print(A)
for i in range(len(A)):
    if A[i] > B[i]:
        count3 += 1
    else:
        pass

if count <= 0 and count2 <= N-2 and count3 <= 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# N = 4
# A = [1,3,2,1]
# B = [1,2,3,2]
count = 0
y = 0

A_B = []

for n in range(N):
    A_B.append([A[n],B[n]])

A_B = sorted(A_B, key = lambda x: (x[1], x[0]))

for n in range(N-1):
    if A_B[n][0] > A_B[n][1]:
        for m in range(n+1, N):
            if A_B[m][0] <= A_B[n][1] and A_B[n][0] <= A_B[m][1]:
                temp = A_B[m][0]
                A_B[m][0] = A_B[n][0]
                A_B[n][0] = temp
                count += 1
                break

for n in range(N):
    if A_B[n][0] > A_B[n][1]:
        y += 1


if y >= 1:
    print('No')
elif count > N-2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    in_number = int(input())
    NumberSequenceA = input()
    NumberSequenceB = input()
    wk_A = sorted(NumberSequenceA)
    wk_B = sorted(NumberSequenceB)
    for i in range(in_number):
      if wk_A[i] <= wk_B[i]:
        pass
      else:
        print('No')
        return 0
    print('Yes')
    return 0

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.sort()
b.sort()
for i, j in zip(a, b):
    if i > j:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

num = 0
for i in range(n):
    if a[i] > b[i]:
        num += 1
if num >= n-2:
    print('No')
    exit()

lst_original = []
for i in range(n):
    lst_original.append(a[i]-b[i])

a.sort()
b.sort()

lst_ato = []
for i in range(n):
    lst_ato.append(a[i]-b[i])
    if a[i] > b[i]:
        print('No')
        exit()

lst_original.sort()
lst_ato.sort()

num_dif = 0
for i in range(n):
    if lst_ato[i] != lst_original[i]:
        num_dif += 1

if num_dif >= n-1:
    print('No')
    exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))


p=[]
for i in range(n):
    p.append([b[i],a[i]])

p.sort()
#print(p)

moto=[]
for i in range(n):
    moto.append(p[i][1])
#print(moto)

a.sort()
b.sort()


kanou=True
for i in range(n):
    ban=bisect.bisect_right(a,b[i])
    #print(ban)
    if(ban<=i):
        kanou=False


if(kanou):
    kasanari=False
    for i in range(n):
        usi=bisect.bisect_right(b,b[i])
        mae=bisect.bisect_left(b,b[i])
        if(a[i] in moto[mae:usi]):
            kasanari=True
    if(not kasanari):
        kanou=False
if(kanou):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def zetubou(a, b):
    sorteda = sorted(a)
    sortedb = sorted(b)
    for ai, bi in zip(sorteda, sortedb):
        if ai > bi:
            return True
    return False

def is_unique(a, b):
    sorteda = sorted(a)
    sortedb = sorted(b)
    for i in range(len(a) - 1):
        if sorteda[i+1] <= sortedb[i]:
            return False
    if len(set(a)) != len(a):
        return False
    if len(set(b)) != len(b):
        return False
    return True

def position_zenbuchigau(a, b):
    sorteda = sorted(a)
    sortedb = sorted(b)
    acomp = {ai: i for i, ai in enumerate(sorteda)}
    bcomp = {bi: i for i, bi in enumerate(sortedb)}
    newa = [acomp[ai] for ai in a]
    newb = [bcomp[bi] for bi in b]
    ng = 0
    for nai, nbi in zip(newa, newb):
        if nai != nbi:
            ng += 1

    if ng == len(a):
        return True
    else:
        return False



n = ni()
a = list(li())
b = list(li())

possible = True

if zetubou(a,b):
    possible = False
elif is_unique(a, b):
    if position_zenbuchigau(a, b):
        possible = False

print("Yes" if possible else "No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
a = []
b = []
for i in range(0, n):
    if aa[i] != bb[i]:
        a.append(aa[i])
        b.append(bb[i])
aa = sorted(a)
bb = sorted(b)
flag = 1
for i in range(0, len(aa)):
    if aa[i] > bb[i]:
        flag = 0
        break
if flag == 1:
    count = 0
    for i in range(0, len(a)):
        if a[i] > b[i]:
            count += 1
        if count // 2 == n - 2:
            flag = 0
            break

if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB=[]
for a, b in zip(A,B):
    AB.append([b,a])
AB.sort()
result=0
for i in range(N-2):
    if result==0:
        for k in range(N):
            P=0
            if AB[k][0]>=AB[k][1]:
                P+=1
                if P==N:
                    result=1
                    break
                else:
                    pass
            else: 
                no=0
                for j in range(N-k-1):
                    if AB[k][0]>=AB[k+j+1][1]:
                        temp=AB[i][1]
                        AB[k][1]=AB[k+j+1][1]
                        AB[k][1]=temp
                        result=1
                        break
                    else:
                        no+=1
                        if no==N-k-1:
                            result = 0
                            break
                        else:
                            pass
    else:
        break

if result == 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
ans2 = 0

for i in range(n):
  if a[i] > b[i]:
    ans2 += 1

a = sorted(a)
b = sorted(b)

for i in range(n):
  if a[i] > b[i]:
    print("No")
    ans += 1
    break
    
if ans2 > n-1 and ans == 0:
  print("No")
elif ans == 0:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ab=[[a[i],b[i]] for i in range(n)]
#print(ab)
a.sort()
b.sort()


for i in range(n):
    if b[i]<a[i]:
        s="No"
        break
else:
    s="Yes"
    #こっちのNoのパターンを省く
    #最大でもN-1回
    ab.sort(key=lambda x:x[1])
    a2=[ab[i][0] for i in range(n)]

    for i in range(n-1):
        a2[i],a[i+1]=a2[i+1],a[i]
        if a2[i]!=a[i]:
            break
    else:
        s="No"
print(s)

    #print(a)
    #print(a2)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

from bisect import bisect_left

#インデックス付きソート
#(index,value)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

A2 = sorted(A)
B2 = sorted(B)

for i in range(N):
    if A2[i]>B2[i]:
        print('No')
        exit()

for i in range(N-1):
    if B2[i]>=A2[i+1]:
        print('Yes')
        exit()

A3 = index_sort(A)
B3 = index_sort(B)

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    p1 = bisect_left(A2,A[bindex])
    A3[p1][0] = i
    A3[i][0] = p1


for i in range(N):
    if A[i]>B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N = INT()
A = sorted(LIST())
B = sorted(LIST())

for i in range(N):
    if A[i] > B[i]:
        No()
        exit()
Yes()

Submission status: Wrong Answer

Solution code:
N=int(input())
List=[[int(j) for j in input().split()] for i in range(2)]

ans = 1
cnt = 0

aa = sorted(List[0])
bb = sorted(List[1])
  
for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1   
    
if cnt < N-2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        exit()

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

A = [-1] * N
B = [-1] * N

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    A[i] = k
    B[j] = k

aToI = {a : i for i, a in enumerate(A)}

cnt = 0
visited = [False] * N
for i, a in enumerate(A):
    if visited[i]:
        continue
    visited[i] = True

    leng = 0
    now = i
    while True:
        b = B[i]
        now = aToI[b]
        if visited[now]:
            break
        leng += 1
        visited[now] = True
    cnt += leng

if cnt <= N - 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

table = collections.defaultdict(set)

for i in range(N):
    table[A[i]].add(B[i])

B.sort()
A.sort()
count = 0
for i in range(N):
    if A[i] <= B[i]:
        if B[i] in table[A[i]]:
            count += 1
    else:
        print("No")
        exit(0)

if count > 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# C - Swaps
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
count2 = 0
count3 = 0

for i in range(len(A)):
    if A[i] > B[i]:
        count += 1
        count2 += 1
    elif A[i] < B[i]:
        count += -1
    else:
        pass

A.sort(reverse=True)
B.sort(reverse=True)
# print(A)
for i in range(len(A)):
    if A[i] > B[i]:
        count3 += 1
    else:
        pass

if count <= 0 and count2 <= N-2 and count3 < 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = sorted(A)
SB = sorted(B)

pair = {}
for a, b in zip(SA, SB):
    if a > b:
        print('No')
        break
    else:
        pair[(a, b)] = 0
else:
    for i in range(n):
        for j in range(i, -1, -1):
            if SA[i] <= SB[j]:
                pair[(SA[i], SB[j])] = 0
            else:
                break
    for a, b in zip(A, B):
        if (a, b) in pair:
            print('Yes')
            break
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
err=0
for i in range(n):
    if a[i]>b[i]:
        err+=1
a1=sorted(a)
b1=sorted(b)
# print(a1)
# print(b1)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        quit()
# print(err)
if err<n-2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

num = 0
lst_original = []
for i in range(n):
    lst_original.append(a[i]-b[i])

a.sort()
b.sort()

lst_ato = []
for i in range(n):
    lst_ato.append(a[i]-b[i])
    if a[i] > b[i]:
        print('No')
        exit()

lst_original.sort()
lst_ato.sort()

num_dif = 0
for i in range(n):
    if lst_ato[i] != lst_original[i]:
        num_dif += 1

if num_dif >= n-1:
    print('No')
    exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math as mp
from itertools import permutations

def l_i():
    arr = [int(a) for a in input().strip().split(' ')]
    return arr
c=0
nm=0
n=int(input())
ar=l_i()
br=l_i()
for i in range(n):
    if(ar[i]<=br[i]):
        c=c+1
    else:
        nm=nm+1

if(n==3 and ar[1]<ar[2]):
    print('No')
elif(n-2>=nm):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
List=[[int(j) for j in input().split()] for i in range(2)]

ans = 1
cnt = 0

aa = sorted(List[0])
bb = sorted(List[1])
  
for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1  

for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1  
    
    
for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1  
    
for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1  
    
    
for i in range(len(List[0])):
  a = List[0][ List[0].index(aa[N-1 - i]) ]
  b = List[1][ List[0].index(aa[N-1 - i]) ]
  num =  List[0].index(aa[N-1 - i])
  
  if a > b:
    ind = List[1].index(bb[N-1- i])
    c = List[0][ind]
    List[0][ind] = a
    List[0][ num ] = c
    cnt = cnt + 1  
    
if cnt < N-2:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
b = np.array([int(x) for x in input().split()])

sa = np.sort(a)
sb = np.sort(b)

fin = False
for ai, bi in zip(sa,sb):
    if ai>bi:
        fin = True
        print("No")
        break

count=0
if fin != True:
    for i in range(n):
        if a[i] > b[i]:
            count+=1
    if count > n-2:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

from bisect import bisect_left
from operator import itemgetter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    C = sorted(A)
    D = sorted(B)
    for i in range(N):
        if C[i] > D[i]:
            print('No')
            return

    E = []
    for ind, a in enumerate(A):
        i = bisect_left(D, a)
        if ind != i:
            print('Yes')
            return
        E.append((a, D[i]))

    F = []
    for i in range(N):
        F.append((A[i], B[i]))
    F.sort()
    
    for i in range(N):
        if F[i] != E[i]:
            print('Yes')
            return 
    
    print('No')
    return 

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

table = collections.defaultdict(set)

for i in range(N):
    table[A[i]].add(B[i])

B.sort()
A.sort()
print(table)
count = 0
for i in range(N):
    if A[i] <= B[i]:
        if B[i] in table[A[i]]:
            count += 1
    else:
        print("No")
        exit(0)

if count > 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# C - Swaps
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
count2 = 0
count3 = 0

for i in range(len(A)):
    if A[i] > B[i]:
        count += 1
        count2 += 1
    elif A[i] < B[i]:
        count += -1
    else:
        pass

A.sort(reverse=True)
B.sort(reverse=True)
# print(A)
for i in range(len(A)):
    if A[i] > B[i]:
        count3 += 1
    else:
        pass

if count == 0 and count2 <= N-2 and count3 < 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
BA = [(b, a) for (b, a) in zip(B, A)]
BA.sort()
C = [a for (b, a) in BA]
A.sort()
B.sort()
vld = all(a <= b for (a, b) in zip(A, B))
cnt = [a == c for a, c in zip(A, C)].count(True)
print('Yes' if cnt > 0 and vld else 'No')

Submission status: Wrong Answer

Solution code:
# C
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))

sal = sorted(al)
sbl = sorted(bl)
for sa, sb in zip(sal, sbl):
    if sa > sb:
        print('No')
        exit()

cl = [a - b for a, b in zip(al, bl)]
plustotal = 0
for c in cl:
    if c > 0:
        plustotal += 1
if plustotal >= n-2:
    print('No')
    exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB=[]
for a, b in zip(A,B):
    AB.append([b,a])
AB.sort()
result=0
for i in range(N-2):
    if result==0:
        for k in range(N):
            P=0
            if AB[k][0]>=AB[k][1]:
                P+=1
                if P==N:
                    result=1
                    break
                else:
                    pass
            else: 
                no=0
                for j in range(N-k-1):
                    if AB[k][0]>=AB[k+j+1][1]:
                        temp=AB[i][1]
                        AB[k][1]=AB[k+j+1][1]
                        AB[k][1]=temp
                        result=1
                        print(AB)
                        break
                    else:
                        no+=1
                        if no==N-k-1:
                            result = 0
                            break
                        else:
                            pass
    else:
        break

if result == 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
        
if (bubble_sort(A) - bubble_sort(B)) <= N-2:
    for i in range(N):
        if A[i] > B[i]:
            print("No")
            exit(0)
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

from bisect import bisect_left

#インデックス付きソート
#(index,value)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

A2 = sorted(A)
B2 = sorted(B)

for i in range(N):
    if A2[i]>B2[i]:
        print('No')
        exit()

for i in range(N-1):
    if B2[i]>=A2[i+1]:
        print('Yes')
        exit()

A3 = index_sort(A)
B3 = index_sort(B)

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    #if aindex==bindex:
    #    print('Yes')
    #    exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    p1 = bisect_left(A2,A[bindex])
    p2 = bisect_left(A2,A[aindex])
    A3[p1][0] = p2
    A3[p2][0] = p1


for i in range(N):
    if A[i]>B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import bisect

N = int(input())
*A, = map(int,input().split())
*B, = map(int,input().split())

A2 = A[:]
B2 = B[:]

A2.sort()
B2.sort()

ans = True
for a,b in zip(A2,B2):
    if a>b :
        ans = False
        break

br = bisect.bisect_right
bl = bisect.bisect_left
if ans :
    ans = False
    for a,b in zip(A,B):
        ai = br(A2,a)-1
        bi = bl(B2,b)
        if A2[ai]<= B2[bi]:
            ans = True
            break

print("Yes" if ans else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

AS = sorted(A)
BS = sorted(B)
for a, b in zip(AS, BS):
    if a > b:
        print("No")
        quit()

c = 0
for a, b in zip(A, B):
    if a <= b:
        c += 1

if c >= 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ab=[[a[i],b[i]] for i in range(n)]
#print(ab)
a.sort()
b.sort()


for i in range(n):
    if b[i]<a[i]:
        s="No"
        break
else:
    s="Yes"
    ab.sort(key=lambda x:x[1])
    for i in range(n-1):
        a[-1-i],a[-2-i]=a[-2-i],a[-1-i]

    a2=[]
    for i in range(n):
        a2.append(ab[i][0])

    if a2==a:
        s="No"

print(s)

    #print(a)
    #print(a2)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    b_s = LI()
    s_a_s = sorted(a_s)
    s_b_s = sorted(b_s)
    d = {}
    for i in range(n):
        d[s_a_s[i]] = s_b_s[i]
        if s_b_s[i] - s_a_s[i] < 0:
            print("No")
            return

    ans = 0
    for i in range(n):
        if d[a_s[i]] == b_s[i]:
            print("Yes")
            return
        if ans >= s_a_s[i]:
            print("Yes")
            return
        ans = s_a_s[i]
        if ans >= s_b_s[i]:
            print("Yes")
            return
        ans = s_b_s[i]
    print("No")

if __name__ == '__main__':
    main()