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()

#インデックス付きソート
#(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
    A3[aindex][0] = bindex
    A3[bindex][0] = aindex 

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

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())))


D = np.sort(B) - np.sort(A)

if sum(D < 0) != 0:
    print('No')

D = B - A

num = sum(D < 0)

if num >= 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()))
d = [b[i]-a[i] for i in range(n)]
l = len(list(filter(lambda x:x<0,d)))
if l >= n - 1:
  ans = 'No'
elif (l == n - 2) & (n%2 == 0):
  ans = 'No'
else:
  a = sorted(a)
  b = sorted(b)
  ans = 'Yes'
  for i in range(n):
    if b[i] - a[i] < 0:
      ans = 'No'
print(ans)

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()

flag = 0
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        flag = 1

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]
a_min=[]
b_min=[]

def detection (a,b):
    for i in range(len(a)-1):
        if a[i]-b[i]>0:
            print("No")
            sys.exit()
    print("Yes")

if min(a)-min(b)>0:
    print("No")
    sys.exit()
else:
    a_min=heapq.nsmallest(2, a)
    b_min=heapq.nsmallest(2, b)
    if a.index(a_min[0])>a.index(a_min[1]):
        a_min[0],a_min[1]=a_min[1],a_min[0]


detection(a_min,b_min)

Submission status: Wrong Answer

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

aa = sorted(a)
bb = sorted(b)

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()

ab = []

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

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


if len(set(aa)) < n:
    print('Yes')
    exit()

for i in range(n):
    if aa[i] == ab[i][0]:
        print('Yes')
        exit()

from collections import defaultdict
d = defaultdict(int)

for i in range(n):
    d[aa[i]] += i

abd = [0]*n

for i in range(n):
    abd[i] = d[ab[i][0]]

q = [abd[0]]
chk = [0]*n
chk[0] = 1

while q:
    x = q.pop()
    if chk[x] == 0:
        chk[x] = 1
        q.append(abd[x])

if sum(chk) != n:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.sort()
b.sort()

a_np = np.array(a)
b_np = np.array(b)
c_np = np.array(a_np - b_np)
flag = 0

for i in c_np:
  if i<0:
    flag = 1

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import bisect as bi
import numpy as np
import sys
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
b.sort()
ab = np.dstack([a,b])
ab = [flatten for inner in ab for flatten in inner]
ab.sort(key=itemgetter(1))

tmplist = []
#tmp = 0
cnt = 0

for i in range(n):
    if ab[i][0] > ab[i][1]:
        index = bi.bisect_left(b,ab[i][0])
        if index == n:
          print('No')
          sys.exit()
        #tmp = ab[index][0]
        for j in range(index,n):
            tmp = ab[j][0]
            if tmp >= ab[i][1]:
                ab[j][0], ab[i][0] = ab[i][0], ab[j][0]
                break
            elif j == n-1:
                print('No')
                sys.exit()
            #ab[index][0] , ab[i][0] = ab[i][0] , ab[index][0]
        cnt += 1
        if cnt > n - 2:
            print('No')
            sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
from sys import exit

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

a = list(sorted(A))
b = list(sorted(A))

c = 0
for i in range(N):
    if a[i] > b[i]:
        print('No')
        exit()
    if A[i] > B[i]:
        c += 1

if c == N - 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split(' ')))
bb = list(map(int, input().split(' ')))
saa = sorted(aa)
sbb = sorted(bb)

hoge = [a > b for a, b in zip(saa, sbb)]
# (1,2)
# (2,1) NG
# (1,2,3)
# (2,1,3) OK
# (1,2,3)
# (2,3,1) NG
memo = dict()
for a, b in zip(saa, sbb):
    memo[(a,b)] = memo.get((a,b), 0) + 1
for a, b in zip(aa, bb):
    memo[(a,b)] = memo.get((a,b), 0) + 1
valid = False
for k, v in memo.items():
    if v >= 2:
        valid = True
if any(hoge) or not valid:
    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_ = sorted(a)
b_ = sorted(b)
f = sum(b_[i]<a_[i] for i in range(n))
if f:
    print("No")
    exit(0)
g = sum(b_[i-1]>=a[i] for i in range(1,n))
if g:
    print("Yes")
    exit(0)
da = dict()
for i in range(n):
    da[a_[i]] = i
ca = list(map(lambda x:da[x],a))
db = dict()
for i in range(n):
    db[b_[i]] = i
cb = list(map(lambda x:db[x],b))
cb2 = [None]*n
for i in range(n):
    cb2[ca[i]] = cb[i]
cnt = 1
c = cb2[0]
while c:
    c = cb2[c]
    cnt += 1
if cnt ==  n:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ng_count = 0
for a, b in zip(A, B):
    if a > b:
        ng_count += 1
swaps = ceil(ng_count / 2)
if swaps > N - 2:
    print("No")
    sys.exit()

sorted_A = sorted(A)
sorted_B = sorted(B)
for a, b in zip(sorted_A, sorted_B):
    if a > b:
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
A=a.copy()
b=list(map(int,input().split()))
B=b.copy()
a=sorted(a)
b=sorted(b)
C=[0 for i in range(n)]
for j in range(n):
    C[j]=(A[j],B[j])
C=sorted(C,key=lambda x:(x[1],x[0]))
D=[0 for i in range(n)]
for i in range(n):
    D[i]=C[i][0]

flag=True
flag2=False
for j in range(n):
    if a[j]>b[j]:
        flag=False
        break
N=max(a)

listss=[[] for i in range(N+1)]
for i in range(n):
    listss[a[i]].append(D[i])
    listss[D[i]].append(a[i])
for j in range(n):
    listss[j]=list(set(listss[j]))
del listss[0]
for j in listss:
    if len(j)==0:
        continue
    elif len(j)!=2:
        flag2=True        
if flag and flag2:
    print("Yes")
else:
    print("No")

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)

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):
        if(a[i]==p[i][1]):
            kasanari=True
            break
    if(not kasanari):
        kanou=False
if(kanou):
    print("Yes")
else:
    print("Noooo")

Submission status: Wrong Answer

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

aa = sorted(a)
bb = sorted(b)

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()

ab = []

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

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


if len(set(aa)) < n:
    print('Yes')
    exit()

for i in range(n):
    if aa[i] == ab[i][0]:
        print('Yes')
        exit()

from collections import defaultdict
d = defaultdict(int)

for i in range(n):
    d[aa[i]] += i

abd = [0]*n

for i in range(n):
    abd[i] = d[ab[i][0]]

q = [abd[0]]
chk = [0]*n
chk[0] = 1

while q:
    x = q.pop()
    if chk[x] == 0:
        chk[x] = 1
        q.append(abd[x])

if sum(chk) == n:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
n = int(input())

al = list(map(int,input().split()))
bl = list(map(int,input().split()))

for a,b in zip(sorted(al),sorted(bl)):
    if b-a < 0:
        print("No")
        sys.exit()

aal = sorted(al)
bbl = sorted(bl)
for i in range(n):
    for j in range(i+1,n):
        if bbl[i] - aal[j] >= 0 and bbl[j] - aal[i] >= 0:
            print("Yes")
            sys.exit()

for i in range(n):
    for j in range(i+1,n):
        if bl[i] - al[j] >= 0 and bl[j] - al[i] >= 0:
            print("Yes")
            sys.exit()
            
for a,b in zip(al,bl):
    if b-a >= 0:
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
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')
        exit()

for i in range(n-1):
    if c[i+1]<=d[i]:
        print('Yes')
        exit()

for i in range(n-1):
    if c[i]==c[i+1]:
        print('Yes')
        exit()
    if d[i]==d[i+1]:
        print('Yes')
        exit()

e = {}
f = {}
for i in range(n):
    e[c[i]]=d[i]
    f[a[i]]=b[i]

ee = {v: k for k, v in e.items()}
ff = {v: k for k, v in f.items()}

for x in a:
    if e[x]==f[x]:
        print('Yes')
        exit()

for x in a:
    y = f[x]
    if ff[e[x]]==ee[y]:
        print('Yes')
        exit()
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)

if max(A) > max(B) or min(B) < min(A):
    print("No")
    exit(0)

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 >= 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import bisect

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

def can(t):
    if b[t] == sb[t]:
        return True
    if b[t] > sb[t]:
        tt = bisect.bisect_left(sb,b[t])
        if sa[tt] <= sb[t]:
            return True
        else:
            return False
    else:
        tt = bisect.bisect_right(sb,b[t])-1
        if sa[t] <= sb[tt]:
            return True
        else:
            return False

for i in range(n):
    if sa[i] > sb[i]:
        print('No')
        exit(0)
for i in range(n):
    if can(i):
        print('Yes')
        exit(0)

Submission status: Wrong Answer

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

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

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

si2i = sorted(range(len(A)), key=lambda x:A[i])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= 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()))
AB = [[A[i],B[i]] for i in range(N)]
AB.sort(key=lambda x:x[1])

A = [[A[i],i] for i in range(N)]
A.sort(key=lambda x:x[0])
da = {}
for i in range(N):
    j = A[i][1]
    da[j] = i 
B.sort()
c0 = [0]*(N+1)
c1 = [0]*N
c2 = [0]*N
A = [A[i][0] for i in range(N)]
for i in range(N-1):
    if A[i]<=B[i+1]:
        c1[i] = 1
    if B[i]<=A[i+1]:
        c2[i] = 1
for i in range(N):
    if A[i]<=B[i]:
        c0[i] = 1
for i in range(N-2):
    c1[i+1] += c1[i]
    c2[i+1] += c2[i]
for i in range(N-1):
    c0[i+1] += c0[i]
A = [AB[i][0] for i in range(N)]
ans = False
for n in range(N):
    m = da[n]
    if n < m:
        if c0[n-1]==n and c0[N-1]-c0[m]==N-m-1 and c1[m-1]-c1[n-1]==m-n and A[n]<=B[n]:
            ans = True
    else:
        if c0[m-1]==m and c0[N-1]-c0[n]==N-n-1 and c2[n-1]-c2[m-1]==n-m and A[n]<=B[n]:
            ans = True
if ans:
    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()))

t = sorted(a)
s = sorted(b)
for i in range(n):
    if t[i] > s[i]:
        print("No")
        exit()
        
b_min = 10**18
a_max = 0
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if b[i] < b_min:
            a_max = a[i]
            b_min = b[i]
            ind = i
        elif b[i] == b_min and a[i] > a_max:
            a_max = a[i]
            ind = i

if ind == -1:
    print("No")
    exit()

t = sorted(a[0:ind] + a[ind+1:])
s = sorted(b[0:ind] + b[ind+1:])
for i in range(n-1):
    if t[i] > s[i]:
        break
else:
    print("Yes")
    exit()
    
diff = 10**18
a_max = 10**10
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if b[i] - a[i] < diff:
            diff = b[i] - a[i]
            ind = i
        elif b[i] - a[i] == diff and a[i] < a_max:
            a_max = a[i]
            ind = i

t = sorted(a[0:ind] + a[ind+1:])
s = sorted(b[0:ind] + b[ind+1:])
for i in range(n-1):
    if t[i] > s[i]:
        break
else:
    print("Yes")
    exit()
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

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

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

Submission status: Wrong Answer

Solution code:

import sys

N = int(input())

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

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

"""
able = 0
nable = 0

for i in range(N):

    if A[i] >= B[i]:
        able += 1
    else:
        nable += 1

"""
A.sort()
B.sort()


for i in range(N):

    if A[i] > B[i]:
        print ("No")
        sys.exit()

print ("Yes")

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
for i in range(n):
  if a[i]>b[i]:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:


# unionfind木構造
# unionfindについてはここhttps://www.slideshare.net/chokudai/union-find-49066733
# グループに属するかの判定(find)や、グループ結合(union)に強い

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
As  = list(map(int, input().split()))
Bs  = list(map(int, input().split()))
As_ind = [(a,i) for i,a in enumerate(As)]
Bs_ind = [(b,i) for i,b in enumerate(Bs)]
# from operator import itemgetter
As_ind.sort()
Bs_ind.sort()


uf = UnionFind(N)
d_list = defaultdict(list)
for A,B in zip(As_ind,Bs_ind):
    # print(A,B)
    if A[0] > B[0]:
        print("No")
        exit()
    uf.union(A[1],B[1])
    d_list[uf.find(A[1])].append(A[0])
    # d_list[uf.find(A[1])].add(A[0])
    # d_list[uf.find(B[1])].add(B[0])

# print(d_list)
# コーナーケース(dの値？))
for k in d_list.keys():
    if len(d_list[k]) > len(set(d_list[k])):
        print("Yes")
        exit()

d_ans = defaultdict(int)
for i in range(N):
    root = uf.find(i)
    d_ans[root] += 1
# print(d_ans)
# print(len(d_ans))
if len(d_ans) >= 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()))

count = 0

flag = True

fa = []
fb = []

for x, y in zip(a, b):
  if x > y:
    count += 1
  fa.append(x)
  fb.append(y)

if count > n-2:
  flag = False

sa = sorted(a, reverse=True)
sb = sorted(b, reverse=True)

for x, y in zip(sa, sb):
  if x > y:
    flag = False
    break

sa = sorted(fa, reverse=True)
sb = sorted(fb, reverse=True)

for x, y in zip(sa, sb):
  if x > y:
    flag = False
    break


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

Submission status: Wrong Answer

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  tmp={}
  for i in range(N):
    if not A[i] in tmp.keys():
      tmp[A[i]]=[]
    tmp[A[i]].append(B[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 
 # print(tmp)
  for i in range(N):
   #print(A[i],B[i])
    if B[i] in tmp[A[i]]:
     # print(B[i])
      print("Yes")
      return
  print("Yes")
      
main()

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()

for i in range(N):
    if A[i] == a[i]:
        print("yes")
        sys.exit()
        
if a[1] > b[0]:
    if A[1] == a[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()))
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
ans=0
if g==0:
    _A=[]
    for i,a in enumerate(A):
        _A.append((i,a))
    _A.sort(key=lambda x:x[1])
    index=[]
    for i in range(N):
        index.append(_A[i][0])
    update=1
    while update:
        update=0
        for i in range(1,N):
            if index[i]<index[i-1]:
                update=1
                buf=index[i-1]
                index[i-1]=index[i]
                index[i]=buf
                ans+=1
        if ans>N-2:
            break
if ans>N-2 or g==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 = 0
AA = sorted(A)
BB = sorted(B)
for z in range(N-2):
  A[A.index(AA[N-z-1])],A[B.index(BB[N-z-1])] = A[B.index(BB[N-z-1])],A[A.index(AA[N-z-1])]
for x in range(N):
  if A[x] > B[x]:
    a = 1                                             
if a == 0:
  print('Yes')
else:
  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()))
An = np.array(A)
Bn = np.array(B)
Cn = Bn - An
A.sort()
B.sort()
Ans = np.array(A)
Bns = np.array(B)
Cns = Bns - Ans
dame = np.count_nonzero(Cn < 0)
dames = np.count_nonzero(Cns < 0)
if dame <= N//2 + N%2 and dames == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a_ = list(map(int, input().split()))
b_ = list(map(int, input().split()))

cmb = [(b_[i],a_[i]) for i in range(n)]
cmb.sort()
a_.sort()
b_.sort()
for i in range(n):
    if a_[i]>b_[i]:
        print("No")
        sys.exit()
a = [cmb[i][1] for i in range(n)]
b = [cmb[i][0] for i in range(n)]
cnt = 0
for i in range(n):
    if a[i]>b[i]:
        cnt += 1
if cnt>=n:
    print("No")
    sys.exit()
"""
i = n-1
j = n-1
while i>0:
    if a[i]<=b[i]:
        i-=1
    else:
        while b[j]<a[i]:
            j-=1
            if j<0:
                print("No")
                sys.exit()
            i-=1
"""            
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
items=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
b.sort()
kaisu = 0

for i in range(1, len(items)):
    position = i
    current = items[i]
    while position > 0 and items[position-1] > current:
        items[position] = items[position-1]
        position -= 1
        kaisu = kaisu + 1
    items[position] = current

if(kaisu > (n-2)):
  print("No")
  sys.exit()

for i in range(n):
  if(items[i] > b[i]):
    print("No")
    sys.exit()
print("Yes")

Submission status: Wrong Answer

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

count = 0
if max(a) > max(b) or min(a) > min(b):
    print('No')
else:
    for i in range(n):
        if a[i] > b[i]:
            count+=1
    if (n%2==0 and count <= n/2)  or count == 0 or count <= n/2:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

sAB = set()
for a,b in zip(A,B):
    sAB.add((a,b))
A.sort()
B.sort()

ans = False
for a,b in zip(A,B):
    if (a,b) in sAB:
        ans = True
        break

for a,b in zip(A,B):
    if a>b :
        ans = False
        break

print("Yes" if ans 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-1:
    print('No')
    exit()

print('Yes')

Submission status: Wrong Answer

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

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
merge = []
for item in a:
    merge.append((item, 0))
for item in b:
    merge.append((item, 1))
merge.sort()

acnt = 0
bcnt = 0
ok = False
prev = 0
for val, check in merge:
    if check == 0:
        acnt += 1
    else:
        bcnt += 1
        if bcnt > acnt:
            print("No")
            exit()
    if check == 0 and prev == 1:
        if bcnt < acnt:
            ok = True
    prev = check
if ok:
    print("Yes")
else:
    dic = dict()
    a_s = sorted(a)
    b_s = sorted(a)
    for aa, bb in zip(a_s, b_s):
        dic[aa] = bb
    to_switch = 0
    for aa, bb in zip(a, b):
        if dic[aa] != bb:
            to_switch += 1
    if to_switch >= n:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
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)
cnt=0
for i in range(n):
  if A[i]>B[i]:
    print('No')
    sys.exit()
  else:
    if a[i]<=b[i]:
      cnt+=1
if cnt>2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import bisect

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

def can(t):
    if b[t] == sb[t]:
        return True
    if b[t] > sb[t]:
        tt = bisect.bisect_left(sb,b[t])
        if sa[tt] <= sb[t]:
            return True
        else:
            return False
    else:
        tt = bisect.bisect_right(sb,b[t])-1
        if sa[tt] <= sb[t]:
            return True
        else:
            return False

for i in range(n):
    if sa[i] > sb[i]:
        print('No')
        exit(0)
for i in range(n):
    if can(i):
        print('Yes')
        exit(0)

Submission status: Wrong Answer

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

swap_cnt = 0
for i in range(n):
  max_ = i
  if a[i]<=b[i]:
  	max_value = a[i]
  else:
    max_value = 0
    
  for j in range(i,n):
    if (a[j]<=b[i])&(a[j]>max_value):
      max_ = j
      max_value = a[j]
  
  if max_ != i:
    #a[i]<=>a[max_]
    swap = a[i]
    a[i] = a[max_]
    a[max_] = swap
    swap_cnt+=1
    #print(i)
    #print(swap_cnt)
  #else:
    #print('pass')
    #print(swap_cnt)
  if a[i]>b[i]:
    swap_cnt = n
    break
if swap_cnt<=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())))

D = B - A

num = sum(D < 0)

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

D = np.sort(B) - np.sort(A)

if sum(D < 0) == 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.sort()
b.sort()

a_np = np.array(a)
b_np = np.array(b)

for i in a_np - b_np:
  if i<0:
    print("No")
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(n) for n in input().split(' ')]
B = [int(n) for n in input().split(' ')]
A.sort()
B.sort()

flag = 0
for i in range(N):
    if A[i] > B[i]:
        flag = 1
        break

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


def main():
    class UnionFind:
        def __init__(self, n):
            # 負  : 根であることを示す。絶対値はランクを示す
            # 非負: 根でないことを示す。値は親を示す
            self.table = [-1] * n
            self.size = [1] * n
            self.group_num = 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 is_same(self, x, y):
            return self.root(x) == self.root(y)

        def get_size(self, x):
            r = self.root(x)
            return self.size[r]

        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
                self.size[r1] += self.size[r2]
                if d1 == d2:
                    self.table[r1] -= 1
            else:
                self.table[r1] = r2
                self.size[r2] += self.size[r1]
            self.group_num -= 1


    n = I()
    A = LI()
    B = LI()
    b_sort = sorted([(b, i) for i, b in enumerate(B)])
    a_sort = sorted([(a, i) for i, a in enumerate(A)])
    U = UnionFind(n)
    for i in range(n):
        if a_sort[i][0] > b_sort[i][0]:
            return 'No'
    for j in range(n):
        if j != n - 1 and a_sort[j + 1][0] <= b_sort[j + 1][0]:
            return 'Yes'
    b_ind_to_a_ind = {}
    for i in range(n):
        b_ind_to_a_ind[b_sort[i][1]] = a_sort[i][1]
    for j in range(n):
        U.union(j, b_ind_to_a_ind[j])
    if U.group_num == 1:
        return 'No'
    else:
        return 'Yes'



print(main())