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,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""



n = onem()
A = l()
B = l()

def count(start,id):
    co = 0
    s = start

    while True:
        s = id[s]
        co += 1
        if s == 0:
            break
    return co

L = []

for i in range(n):
    L.append([A[i],B[i]])
L.sort(key=lambda x:x[1])
p = sorted(range(n) , key = lambda i:L[i][0])
A.sort()



bo1 = all(A[i] <= L[i][1] for i in range(n))
bo2 = any(A[i+1] <= B[i] for i in range(n-1))
bo3 = count(0,p) <= n-2

print("Yes" if (bo1 and (bo2 or bo3)) else "No")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""



n = onem()
A = l()
B = l()

def count(start,id):
    co = 0
    s = start

    while True:
        s = id[s]
        co += 1
        if s == 0:
            break
    return co

L = []

for i in range(n):
    L.append([A[i],B[i]])
L.sort(key=lambda x:x[1])

A.sort()
p = sorted(range(n) , key = lambda i:L[i][0])

bo1 = all(A[i] <= L[i][1] for i in range(n))
bo2 = any(A[i+1] <= B[i] for i in range(n-1))
bo3 = count(0,p) <= n-2

print("Yes" if (bo1 and (bo2 or bo3)) else "No")

Submission status: Wrong Answer

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

sorta = list(sorted(zip(a, range(n)), key=lambda tup: tup[0]))
sortb = list(sorted(zip(b, range(n)), key=lambda tup: tup[0]))

possible = all(sai[0] <= sbi[0] for sai, sbi in zip(sorta, sortb))
already = any(sai[1] <= sbi[1] for sai, sbi in zip(sorta, sortb))

print('Yes' if possible and already else 'No')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ar = np.array(sorted(a))
br = np.array(sorted(b))

print('Yes' if all(ar <= br) else 'No')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ar = np.array(sorted(a))
br = np.array(sorted(b))

print('Yes' if all(ar <= br) else 'Yo')

Submission status: Wrong Answer

Solution code:
class Unionfind:

    __slots__ = ['parents','sizes']

    def __init__(self, n):
        self.parents = list(range(n))
        self.sizes = [1]*n

    def root(self, x):
        if self.parents[x] == x:
            return x
        else:
            root_x = self.root(self.parents[x])
            self.parents[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.sizes[x] += self.sizes[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    # 集合自体の数 ({1,2}, {3}, {4} : kind -> 3)
    def kind(self):
        for v in range(N):
            self.root(v)
        return len(list(set(self.parents)))

    # xが属する集合の要素の数　({1,2,3} : size(2) -> 3)
    def size(self, x):
        self.sizes[x] = self.sizes[self.root(x)]
        return self.sizes[x]

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = sorted(enumerate(A), key=lambda x : x[1])
sB = sorted(enumerate(B), key=lambda x : x[1])

# 必要条件
if not all(a <= b for (i, a), (j, b) in zip(sA, sB)):
    print("No")
    exit()

uf = Unionfind(N)
# i -> j　に移動する
for (i, a), (j, b) in zip(sA, sB):
    uf.unite(i, j)

# サイクル数が２つ以上なら高々N-2回で理想の列が作れる
if uf.kind() > 1:
    print("Yes")
    exit()

# 以下サイクル数が１つだがN-2回以下で条件を満たすような例を弾く
# sB[i] < sA[i+1]のようなiが存在すれば sA[i] と sA[i+1]をスワップする(目標とする列)
# サイクルが２つに分かれるので条件を満たす
if any(sB[i][1] <= sA[i+1][1] for i in range(N-1)):
    print("Yes")
    exit()

#　任意のiについてsB[i] < sA[i+1]なら sB[i] と sA[i]を対応させるしかない
# AとBをそれぞれソートした列が目標の列となってこれはN-1回かかるので不適
print("No")

Submission status: Wrong Answer

Solution code:
class Unionfind:

    __slots__ = ['parents','sizes']

    def __init__(self, n):
        self.parents = list(range(n))
        self.sizes = [1]*n

    def root(self, x):
        if self.parents[x] == x:
            return x
        else:
            root_x = self.root(self.parents[x])
            self.parents[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.sizes[x] += self.sizes[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    # 集合自体の数 ({1,2}, {3}, {4} : kind -> 3)
    def kind(self):
        for v in range(N):
            self.root(v)
        return len(list(set(self.parents)))

    # xが属する集合の要素の数　({1,2,3} : size(2) -> 3)
    def size(self, x):
        self.sizes[x] = self.sizes[self.root(x)]
        return self.sizes[x]

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = sorted(enumerate(A), key=lambda x : x[1])
sB = sorted(enumerate(B), key=lambda x : x[1])

# 必要条件
if not all(a <= b for (i, a), (j, b) in zip(sA, sB)):
    print("No")
    exit()

uf = Unionfind(N)
# aiをbjに移動する
for (i, a), (j, b) in zip(sA, sB):
    uf.unite(i, j)

# サイクル数が２つ以上なら高々N-2回で理想の列が作れる
if uf.kind() > 1:
    print("Yes")
    exit()

# 以下サイクル数が１つだがN-2回以下で条件を満たすような例を弾く
# sB[i] < sA[i+1]のようなiが存在すれば sA[i] と sA[i+1]をスワップする(目標とする列)
# サイクルが２つに分かれるので条件を満たす
if any(sB[i] <= sA[i+1] for i in range(N-1)):
    print("Yes")
    exit()

#　任意のiについてsB[i] < sA[i+1]なら sB[i] と sA[i]を対応させるしかない
# AとBをそれぞれソートした列が目標の列となってこれはN-1回かかるので不適
print("No")

Submission status: Wrong Answer

Solution code:
class Unionfind:

    __slots__ = ['parents','sizes']

    def __init__(self, n):
        self.parents = list(range(n))
        self.sizes = [1]*n

    def root(self, x):
        if self.parents[x] == x:
            return x
        else:
            root_x = self.root(self.parents[x])
            self.parents[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.sizes[x] < self.sizes[y]:
            x, y = y, x
        self.sizes[x] += self.sizes[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    # 集合自体の数 ({1,2}, {3}, {4} : kind -> 3)
    def kind(self):
        for v in range(N):
            self.root(v)
        return len(list(set(self.parents)))

    # xが属する集合の要素の数　({1,2,3} : size(2) -> 3)
    def size(self, x):
        self.sizes[x] = self.sizes[self.root(x)]
        return self.sizes[x]

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = sorted(enumerate(A), key=lambda x : x[1])
sB = sorted(enumerate(B), key=lambda x : x[1])

# 必要条件
if not all(a <= b for (i, a), (j, b) in zip(sA, sB)):
    print("No")
    exit()

uf = Unionfind(N)
# aiをbjに移動する
for (i, a), (j, b) in zip(sA, sB):
    uf.unite(i, j)

# サイクル数が２つ以上なら高々N-2回で理想の列が作れる
if uf.kind() > 1:
    print("Yes")
    exit()

# 以下サイクル数が１つだがN-2回以下で条件を満たすような例を弾く
# sB[i] < sA[i+1]のようなiが存在すれば sA[i] と sA[i+1]をスワップする(目標とする列)
# サイクルが２つに分かれるので条件を満たす
if any(sB[i] < sA[i+1] for i in range(N-1)):
    print("Yes")
    exit()

#　任意のiについてsB[i] < sA[i+1]なら sB[i] と sA[i]を対応させるしかない
# AとBをそれぞれソートした列が目標の列となってこれはN-1回かかるので不適
print("No")

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy
input = sys.stdin.readline

N = int(input())
A0 = list(map(int, input().split()))
B0 = list(map(int, input().split()))



# sort B with A
B1 = []
for i, b in enumerate(B0):
	B1.append((b, i))
B1.sort()
A = []
B = []
for b, i in B1:
	B.append(b)
	A.append(A0[i])

#print('A={}'.format(A))
#print('B={}'.format(B))



# count cyclic components
C0 = deepcopy(A)
C1 = []
for i, c in enumerate(C0):
	C1.append((c, i))
C1.sort()
C = []
for c, i in C1:
    C.append(c)

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

#print('A_sort={}'.format(C1))

num_set = set([i for i in range(1, N)])
components = 0
prev = 1
while num_set:
	c, i = C1[prev]
	if i in num_set:
		num_set.discard(i)
		prev = i
	else:
		prev = num_set.pop()
		components += 1

#print('components={}'.format(components))

if components != 1:
	print('Yes')
else:
    ok = False
    for i in range(1, N):
        if C[i] <= B[i - 1]:
            ok = True
            break
    if ok:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy
input = sys.stdin.readline

N = int(input())
A0 = list(map(int, input().split()))
B0 = list(map(int, input().split()))



# sort B with A
B1 = []
for i, b in enumerate(B0):
	B1.append((b, i))
B1.sort()
A = []
B = []
for b, i in B1:
	B.append(b)
	A.append(A0[i])

#print('A={}'.format(A))
#print('B={}'.format(B))



# count cyclic components
C0 = deepcopy(A)
C1 = []
for i, c in enumerate(C0):
	C1.append((c, i))
C1.sort()

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

#print('A_sort={}'.format(C1))

num_set = set([i for i in range(1, N)])
components = 0
prev = 0
while num_set:
	c, i = C1[prev]
	if i in num_set:
		num_set.discard(i)
		prev = i
	else:
		prep = num_set.pop()
		components += 1

#print('components={}'.format(components))

if components != 1:
	print('Yes')
else:
    ok = False
    for i in range(1, N):
        if A[i] <= B[i - 1]:
            ok = True
            break
    if ok:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy
input = sys.stdin.readline

N = int(input())
A0 = list(map(int, input().split()))
B0 = list(map(int, input().split()))



# sort B with A
B1 = []
for i, b in enumerate(B0):
	B1.append((b, i))
B1.sort()
A = []
B = []
for b, i in B1:
	B.append(b)
	A.append(A0[i])

print('A={}'.format(A))
print('B={}'.format(B))



# count cyclic components
C0 = deepcopy(A)
C1 = []
for i, c in enumerate(C0):
	C1.append((c, i))
C1.sort()

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

print('A_sort={}'.format(C1))

num_set = set([i for i in range(1, N)])
components = 0
prev = 0
while num_set:
	c, i = C1[prev]
	if i in num_set:
		num_set.discard(i)
		prev = i
	else:
		prep = num_set.pop()
		components += 1

print('components={}'.format(components))

if components != 1:
	print('Yes')
else:
    ok = False
    for i in range(1, N):
        if A[i] <= B[i - 1]:
            ok = True
            break
    if ok:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
Bsi = np.argsort(B)
A2 = A[Bsi]
Bs = B[Bsi]
A2si = np.argsort(A2)
As = A2[A2si]
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    D = A2-As
    if any(D == 0):
        ans = 'Yes'
    elif all(As[1::]-Bs[:-1:] > 0):
        psum = A2si[0]
        for i,pi in enumerate(A2si[1:-1],1):
            psum += pi
            if psum == int(i*(i+1)/2):
                ans = 'Yes'
                break
        else:
            ans = 'No'
    else:
        ans = 'Yes'
        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
Bsi = np.argsort(B)
A2 = A[Bsi]
Bs = B[Bsi]
A2si = np.argsort(A2)
As = A2[A2si]
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    D = A2-As
    if any(D == 0):
        ans = 'Yes'
    else:
        psum = A2si[0]
        for i,pi in enumerate(A2si[1:-1],1):
            psum += pi
            if psum == np.sum(np.arange(0,i+1)):
                ans = 'Yes'
                break
        else:
            ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N=int(input())
    A=sorted(map(int,input().split()))
    B=sorted(map(int,input().split()))
    for i in range(N):
        if A[i]>B[i]:
            print("No")
            return

    print("Yes")


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

res = B-A
ans = np.count_nonzero(res < 0)

if ans:
	print('No')
else:
	print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import deque
from operator import itemgetter


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

info = [(a[i], b[i]) for i in range(n)]
info = sorted(info, key = itemgetter(1))
for i in range(n):
    a[i], b[i] = info[i]

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])
while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True

for i in range(n):
    if not used[i]:
        print("Yes")
        exit()

for i in range(n):
    if s[i+1] >= t[i]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque
from operator import itemgetter


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
info = [(a[i], b[i]) for i in range(n)]
info = sorted(info, key = itemgetter(1))
for i in range(n):
    a[i], b[i] = info[i]

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)
        graph[v].append(u)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])
while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True
for i in range(n):
    if not used[i]:
        print("Yes")
        exit()
        
for i in range(n):
    if s[i+1] >= t[i]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque
from operator import itemgetter


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

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)
        graph[v].append(u)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])
while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True
for i in range(n):
    if not used[i]:
        print("Yes")
        exit()
        
for i in range(n):
    if s[i+1] >= t[i]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
from collections import deque
from operator import itemgetter


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

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()

for i in range(n):
    if t[i] <= s[i+1]:
        print("Yes")
        exit()

sorted_a = sorted(zip(a, range(len(a))))
graph = [[] for i in range(n)]
for i in range(n):
    u = i
    v = sorted_a[i][1]
    if u != v:
        graph[u].append(v)
        graph[v].append(u)

used = [False]*n
pos = 0
used[pos] = True
q = deque([pos])

while q:
    pos = q.pop()
    for next_pos in graph[pos]:
        if used[next_pos]:
            continue
        q.append(next_pos)
        used[next_pos] = True

for i in range(n):
    if not used[i]:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB = sorted(zip(A,B), key = lambda x:x[1])
A2,Bs = zip(*AB)
A2 = np.array(A2)
Bs = np.array(Bs)
As = np.sort(A)
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    D = A2-As
    if any(D == 0):
        ans = 'Yes'
    elif all(As[1::]-Bs[:-1:] > 0):
        ans = 'No'
    else:
        ans = 'Yes'
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
a = input().split(" ")
b = input().split(" ")

s_a = sorted(a)
s_b = sorted(b)

t_b = ["-1"]*len(s_b)

for i, v in enumerate(s_a):
    pos = a.index(v)
    if (pos == i):
        print("Yes")
        exit()
    else:
        t_b[pos] = s_b[i]

for i,v in enumerate(s_b):
    j = t_b.index(v)
    if (t_b[i] == s_b[j]):
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A1=A[:]
B1=B[:]
change,change1=0,0
cnt=0

A1.sort()
B1.sort()

for i in range(N):
  if B1[i]-A1[i]<0:
    cnt += 1
if cnt==0:
  for i in range(N):
    if B[i]-B1[i]!=0:
      change +=1
    if A[i]-A1[i]!=0:
      change1 +=1
  if (change+change1)/2<=N-2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A1=A[:]
B1=B[:]
change=0
cnt=0
V=[]
for i in range(N):
  V.append([B[i],i])
A1.sort()
B1.sort()
for i in range(N):
  if B1[i]-A1[i]<0:
    cnt += 1
if cnt==0:
  for i in range(N):
    if B[i]-B1[i]!=0:
      change +=1
  if change<=N-2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A1=A[:]
B1=B[:]
change=0
cnt=0
V=[]
for i in range(N):
  V.append([B[i],i])
A1.sort()
B1.sort()
for i in range(N):
  if B1[i]-A1[i]<0:
    cnt += 1
if cnt==0:
  for i in range(N):
    if B[i]-B1[i]!=0:
      change +=1
  if change<=N-2:
    print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
As = np.sort(A)
Bs = np.sort(B)
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    Ar = np.argsort(A)
    Ari = (np.where(Ar==0))[0][0]
    D = np.append(Ar[Ari:N],Ar[0:Ari])
    if np.all(np.equal(D, np.arange(0,N,1))):
        ans = 'No'
    else:
        ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def calc(n, A, B):
    count = 0
    for i in range(n):#scanB
        #print('i=',i)#Debug
        if A[i] <= B[i]:
            continue
        elif i < n-1:
            for j in range(i+1,n):#scanA
                #print(f'i={i},j={j}')
                if A[j] <= B[i]:
                    A[j],A[i] = A[i],A[j]
                    count += 1
                    if count > n-2:
                        return 'No'
                    #print(f'swap:{count}')
                    #print(f'A:{A}')
                    #print(f'B:{B}')
                    break
                elif j == n-1:
                    return 'No'
        else:
            return 'No'
    
    return 'Yes'

                
#main

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

#print(f'A:{A}')
#print(f'B:{B}')

pair = list(zip(A,B))
pair.sort(key=itemgetter(1))#sortB

A, B = zip(*pair)

ltA = list(A)
ltB = list(B)

#print(f'A:{ltA}')
#print(f'B:{ltB}')

#print(f'pair:{pair}')

print(calc(n,ltA,ltB))#for stdout

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
As = np.sort(A)
Bs = np.sort(B)
C = Bs-As
if any(C[C<0]):
    ans = 'No'
else:
    Ar = np.argsort(A)
    if Ar[N-1] == 0:
        if np.all(np.equal(Ar[0:-1:],np.arange(1,N,1))):
            ans = 'No'
    elif Ar[0] == N-1:
        if np.all(np.equal(Ar[1::],np.arange(0,N-1,1))):
            ans = 'No'
    else:
        ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(n, aaa, bbb):
    aai = sorted(enumerate(aaa), key=itemgetter(1))
    bbi = sorted(enumerate(bbb), key=itemgetter(1))
    uft = UnionFind(n)
    for (ai, a), (bi, b) in zip(aai, bbi):
        if a > b:
            return False
        uft.union(ai, bi)
    if sum(r < 0 for r in uft.table) > 1:
        return True
    return any(a >= b for (ai, a), (bi, b) in zip(aai[1:], bbi))


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print('Yes' if solve(n, aaa, bbb) else 'No')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(n, aaa, bbb):
    aai = sorted(enumerate(aaa), key=itemgetter(1))
    bbi = sorted(enumerate(bbb), key=itemgetter(1))
    uft = UnionFind(n)
    for (ai, a), (bi, b) in zip(aai, bbi):
        if a > b:
            return False
        uft.union(ai, bi)
    asc_check = sum(r < 0 for r in uft.table) > 1

    bbi = sorted(bbi, key=lambda x: (x[1], -x[0]))
    uft = UnionFind(n)
    for (ai, a), (bi, b) in zip(aai, bbi):
        uft.union(ai, bi)
    dsc_check = sum(r < 0 for r in uft.table) > 1

    return asc_check or dsc_check


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print('Yes' if solve(n, aaa, bbb) else 'No')

Submission status: Wrong Answer

Solution code:
print('Yes')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter


class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n

    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]

    def find(self, x, y):
        return self._root(x) == self._root(y)

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


def solve(n, aaa, bbb):
    aai = sorted(enumerate(aaa), key=itemgetter(1))
    bbi = sorted(enumerate(bbb), key=itemgetter(1))
    uft = UnionFind(n)
    for (ai, a), (bi, b) in zip(aai, bbi):
        if a > b:
            return False
        uft.union(ai, bi)
    return sum(r < 0 for r in uft.table) > 1


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print('Yes' if solve(n, aaa, bbb) else 'No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import collections

N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
                
s = 0
count = 0 
c = collections.Counter(a)
if len(c) != N:
    print("Yes")
       
elif a[0] > b[1]:
    while A[0] < a[0]:
        s = a.index(A[0])
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")
    else:
        print("Yes")

else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
                

    

s = 0
count = 0
if a[0] > b[1]:
    while A[0] < a[0]:
        s = a.index(A[0])
        A[0] = A[s]
        count +=1
        if a.count(A[0]) != 1:
            print("Yes")
            sys.exit()
    if count > N - 2:
        print("No")
    else:
        print("Yes")

else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = np.array(sorted(list(map(int,input().split()))))
B = np.array(sorted(list(map(int,input().split()))))

if (np.any(A > B)):
  print("No")
elif (np.any(A[1:] > B[:-1])):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = np.array(sorted(list(map(int,input().split()))))
B = np.array(sorted(list(map(int,input().split()))))

if (np.any(A > B)):
  print("No")
elif (np.all(A[1:] > B[:-1])):
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
A = np.array(sorted(list(map(int,input().split()))))
B = np.array(sorted(list(map(int,input().split()))))

if (np.any(A > B)):
  print("No")
elif (np.any(A[1:] >= B[:-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 = [[a[i], b[i]] for i in range(n)]
ab.sort(key=lambda x:x[1])

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

a2 = [[a[i], i] for i in range(n)]
a2.sort(key=lambda x:x[0])

flag1 = 0
for i in range(n):
    if a2[i][0] > b[i]:
        flag1 = 1

flag2 = 1
idx = a2[0][1]
cnt = 0
while idx != 0:
    idx = a2[idx][1]
    cnt += 1

if cnt == n-1:
    for i in range(n-1):
        if a[i+1] <= b[i]:
            flag2=0
            break
else:
    flag2 = 0

if flag1 == 1 or flag2 == 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()))

a.sort()
b.sort()

c = 0

for i in range(n):
    if a[i] > b[i]:
        print('No')
        c = 1
        break

for i in range(n-1):
    if a[i] > b[i+1]:
        print('No')
        c = 1
        break

if c == 0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a.sort()
b.sort()

c = 0

for i in range(n):
    if a[i] > b[i]:
        print('No')
        c = 1
        break

for i in range(n-1):
    if a[i] > b[i+1]:
        print('No')
        c = 1
        break

if c == 1:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = sorted(list(zip(b, a)))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
    
pos = {}
s = [0] * n
for i in range(n):
  pos[a[i]] = i
  if i > 0 and a[i] <= b[i - 1]:
    s[i] = 1
for i in range(1, n):
  s[i] += s[i - 1]

for i, (x, y) in enumerate(l):
  if x >= y:
    if y >= a[i] or s[i] - s[pos[y]] == i - pos[y]:
      print('Yes')
      exit()
 
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = sorted(list(zip(b, a)))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
    
bound = a[n - 1] + 1
for i in range(1, n):
  if a[i] <= b[i - 1]:
    bound = a[i - 1]
    break
 
p = 0
for i, (x, y) in enumerate(l):
  if x >= y:
    if y >= a[i] or y >= bound:
      print('Yes')
      exit()
 
print('No')