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 bisect
from collections import defaultdict
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_A = sorted(A)
sort_B = sorted(B)
if all(a > b for a, b in zip(A, B)):  # N子動かす必要がある
    print("No")
    exit()

D = defaultdict(int)
for a in sort_A:
    ind = bisect.bisect_left(sort_B, a)
    D[a] = N-ind

for a, b in zip(A, B):
    if a <= b:
        if D[a] == 1:
            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()))

for a, b in zip(A, B):
    if a <= b:
        break
else:
    print('no')
    exit()

A.sort()
B.sort()

for i in range(N):
    if A[i] > B[i]:
        print('No')
        exit()
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 = sorted(A)
B_sort = sorted(B)
rep = {}
for i, (a, b) in enumerate(zip(A_sort, B_sort)):
    if a > b:
        print("No")
        exit()
    if a < b:
        if a not in rep:
            rep[a] = {b}
        else:
            rep[a] += {b}
c = 0
for a, b in zip(A, B):
    if a == b:
        print("Yes")
        exit()
    if a <= b:
        c += 1
    if a in rep:
        if b in rep[a]:
            print("Yes")
            exit()
if c == len(A):
    print("Yes")
else:
    print("No")

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

    for ind, a in enumerate(C):
        i = bisect_left(D, a)
        if ind != i:
            print('Yes')
            return
    E = []
    for i in range(N):
        E.append((C[i-1], D[i]))
    
    E.sort(key=itemgetter(1))
    E.sort(key=itemgetter(0))

    F = []
    for i in range(N):
        F.append((A[i], B[i]))
    F.sort(key=itemgetter(1))
    F.sort(key=itemgetter(0))
    
    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:
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][0] < 0:
                break
            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:

import sys

N = int(input())

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

B = list(map(int,input().split()))
"""
A2 = []
B2 = []

for i in range(N):
    A2.append([A[i],i])
for j in range(N):
    B2.append([B[i],i])

A2.sort()
B2.sort()

"""
na = []
nb = []
able = 0
nable = 0


for i in range(N):

    if A[i] <= B[i]:
        able += 1
    else:
        nable += 1
        na.append(A[i])
        nb.append(B[i])

na.sort()
nb.sort()
lop = 0

for i in range(nable):
    if na <= nb:
        lop += 1

if lop > 0:
    nable -= 1

if nable > N-2:
    print ("No")
    sys.exit()

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:
# -*- coding: utf-8 -*-

import math
import numpy as np

N = int(input())
A_seq = input().split()
B_seq = input().split()

A_seq = list(map(int, A_seq))
B_seq = list(map(int, B_seq))

A_seq = np.array(A_seq)
B_seq = np.array(B_seq)

def func(A_seq, B_seq, N):
    counts = 0
    for i in range(N):
        if(A_seq[i]==B_seq[i]):
            pass
        else:
            dif_old = B_seq[i]-A_seq[i]
            for j in range(i+1, N):
                dif_new = B_seq[i]-A_seq[j]
                if(dif_old > 0):
                    if(((dif_new>=0))and((abs(dif_new)-abs(dif_old))<0)):
                        A_seq[i] = A_seq[j]
                        counts += 1
                        dif_old = dif_new
                else:
                    if(dif_new>=0):
                        A_seq[i] = A_seq[j]
                        counts += 1
                        dif_old = dif_new
    return counts
                        
if np.all(np.all(A_seq <= B_seq)):
    print('Yes')
else:
    N_1 = func(A_seq, B_seq, N)
    if N_1 > N-2:
        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_new=sorted(a)
b_new=sorted(b)
ans='Yes'
for i in range(0,n):
  if a_new[i]>b_new[i]:
    ans='No'
    break
if a_new[-1]<=b_new[-2]:
  ans='Yes'
print(ans)

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        
        print('No')
        exit()
    else:
        pass

if count <= 0 and count2 <= N-2 and count3 <= 0:
    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] and sa[t] <= sb[tt]:
            return True
        else:
            return False
    else:
        tt = bisect.bisect_right(sb,b[t])-1
        if sa[t] <= sb[tt] and 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)
print('No')

Submission status: Wrong Answer

Solution code:
import bisect
from collections import defaultdict
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_A = sorted(A)
sort_B = sorted(B)
if all(a > b for a, b in zip(A, B)):  # N子動かす必要がある
    print("No")
    exit()

D = defaultdict(int)
for a in sort_A:
    ind = bisect.bisect_left(sort_B, a)
    D[a] = N-ind

for a, b in zip(A, B):
    if a <= b:
        if D[a] == 0:
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A_s, B_s = sorted(A), sorted(B)
if any(a > b for a, b in zip(A_s, B_s)):
    print("No")
    quit()
if len(set(B)) < N:
    print("Yes")
    quit()
perm = [0] * N
A_idx = [(a, i) for i, a in enumerate(A)]
A_idx.sort()
B = [B[idx] for _, idx in A_idx]
B_idx = [(b, i) for i, b in enumerate(B)]
B_idx.sort()
for i, (_, idx) in enumerate(B_idx):
    perm[idx] = i
cycle_len = 0
used = [False] * N
for i in range(N):
    if used[i]:
        continue
    cnt = 0
    now = i
    while not used[now]:
        used[now] = True
        cnt += 1
        now = perm[now]
    cycle_len += cnt - 1
if cycle_len == N - 1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import collections

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

cnt_A = collections.Counter(A)
cnt_B = collections.Counter(B)

cnt_over = 0
for i in range(N+1, max(B)+1):
    cnt_over += cnt_B[i]

A.sort()
B.sort()

A = A[:len(A)-cnt_over]
B = B[:len(B)-cnt_over]

if 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],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 A[i+1]<=B[i]:
        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()))
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
ans=0
for i in range(N):
    if A[i]>B[i]:
        ans+=1

if (ans//2)+ans%2>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.sort()
b.sort()
dekiru=1
ka=0
for i in range(n):
	if a[i]>b[i]:
		ka+=1
if ka!=n:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		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()))

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

mm = max(aa)

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()
    if i != n-1 and mm <= bb[i]:
        print('Yes')
        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()

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:
n = int(input())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 

count = 0
#aの方が最大値が大きい or bの方が最小値が小さい
if max(a) > max(b) or min(a) > min(b):
    print('No')
else:
    #swapしなければならない場所の数
    for i in range(n):
        if a[i] > b[i]:
            count+=1
        elif a[i] < b[i]:
            count -=1
    #問題なし?
    if count == 0:
        print('Yes')
    # ２の倍数かつ回数が半分以下 or ２の倍数以外かつ回数が半分以下
    elif (n%2==0 and count%2 == 0) or (count%2 == 0):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

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

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}
A=[compression_dict[a] for a in A]
B=[compression_dict[a] for a in B]


SA=sorted(A)
SB=sorted(B)

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

# BIT(BIT-indexed tree)
LEN=max(max(A),max(B))+10

BIT=[0]*(LEN+1)# 1-indexedなtree

def update(v,w):# index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in A:
    update(a,1)

BIT2=[0]*(LEN+1)# 1-indexedなtree

def update2(v,w):# index vにwを加える
    while v<=LEN:
        BIT2[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue2(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT2[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in B:
    update2(a,1)

#for i in range(1,4):
#    print(getvalue(i),getvalue2(i))

for i in range(N):
    a=A[i]
    b=B[i]

    if a>b:
        continue

    update(a,-1)
    update2(b,-1)

    #for i in range(1,4):
    #    print(getvalue(i),getvalue2(i))

    #print(getvalue(a),getvalue2(a),getvalue(b),getvalue2(b))

    if getvalue(a)<=getvalue2(a) and getvalue(b)<=getvalue2(b):
        print("Yes")
        sys.exit()
    else:
        update(a,1)
        update2(b,1)

print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
import bisect as bs


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    B = list(map(int, args[2].split()))

    sA = sorted(A)
    sB = sorted(B)

    ret = all(np.greater_equal(np.array(sB), np.array(sA)))

    ab = sorted(zip(A, B))
    sA, uB = zip(*ab)
    uB = list(uB)
    count = 0
    for i in range(n-1):
        if uB[i] >= uB[i+1]:
            for j in range(i+1, n):
                if uB[i] >= uB[j]:
                    uB[i], uB[j] = uB[j], uB[i]
                    count += 1
                    break

    ret = ret and (n-2 <= count)

    return 'Yes' if ret else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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 = max(cnt, leng)

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls0 = ril()
ls1 = ril()

a0 = sorted(ls0)
a1 = sorted(ls1)
for x, y in zip(a0, a1):
    if x > y:
        print('No')
        exit()

ls = list(zip(ls0, ls1))
ls.sort(key=lambda x: x[1])
a, b = ls[0]
if a <= b:
    print('Yes')
    exit()

for x, _ in ls[1:-1]:
    if a <= x:
        print('Yes')
        exit()
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()))
aa=[[a[i],i] for i in range(N)]
bb=[[b[i],i] for i in range(N)]
aa.sort()
bb.sort()


for i in range(N):
    if aa[i][0]>bb[i][0]:
        print("No")
        sys.exit()

for i in range(N-1):
    if aa[i][0]==aa[i+1][0] or bb[i][0]==bb[i+1][0]:
        print("Yes")
        sys.exit()

for i in range(1,N):
    if aa[i][0]<=bb[i-1][0]:
        print("Yes")
        sys.exit()


dic={}
for i in range(N):
    dic[aa[i][0]]=i

inij=1
cycle=1
j=inij

while True:
    j=dic[a[j]]
    if j==inij:
        break
    cycle+=1

print("Yes" if cycle<N else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A1 = [(i,A[i]) for i in range(N)]
B1 = [(i,B[i]) for i in range(N)]
A1 = sorted(A1,key=lambda x:x[1])
A2 = {}
for i in range(N):
    A2[A1[i]] = i
B1 = sorted(B1,key=lambda x:x[1])
flag = 0
for i in range(N):
    if A1[i][1]>B1[i][1]:
        flag = 1
        break
if flag==1:
    judge = "No"
else:
    for i in range(N):
        if A1[i][0]==B1[i][0]:
            flag = 2
            break
        ind1 = A2[(i,A[i])]
        s,_ = B1[ind1]
        ind2 = A2[(s,A[s])]
        t,_ = B1[ind2]
        if i==t:
            flag=2
            break
    if flag==2:
        judge = "Yes"
    else:
        judge = "No"
print(judge)

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
for i in range(N):
    if A[i]>B[i]:
        ans+=1

if ans//2>N-2 or g==1:
    print("No")
else:
    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 idxb <= idxa or bisect_right(arr, idxa) == bisect_right(arr, idxb):
        print('Yes')
        break
else:
    print('No')

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()]
a1=sorted(a)
b1=sorted(b)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        exit()
cnt=0
for i in range(n):
    if a[i]>b[i]:
        cnt+=1
print("Yes" if cnt<n-1 else "No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
b = sorted([int(i) for i in input().split()])
ans = 'Yes'
for i in range(n):
    if b[i] < a[i]:
        ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())
a=list(map(int, input().split())) 
b=list(map(int, input().split())) 
 
if (max(b) < max(a) or min(b) < min(a)):
    print ('No')
 
else :
    count = 0
    for i in range(len(a)):
        if (a[i] > b[i]):
            count = count + 1

    a.sort()
    b.sort()

    if (count > n-2):
        print('No')
    else:
        for i in range(len(a)):
            if (a[i] > b[i]):
                print('No')
                break

            elif (i == len(a)-1):
                print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    Ai=np.argsort(A)
    Bi=np.argsort(B)
    for a_i,b_i in zip(Ai,Bi):
        if A[a_i]>B[b_i]:
            print('No')
            quit()
    d={}
    z=[]
    for i in range(N):
        if A[Bi[i]]==A[Ai[i]]:
            print('Yes')
            quit()
        if not A[Bi[i]] in d:
            d[A[Bi[i]]]=[Bi[i]]
            z.append(A[Bi[i]])
        else:
            d[A[Bi[i]]].append(Bi[i])
    for i in z:
        l=d[i]
        for j in l:
            m=d[A[Ai[j]]]
            for k in m:
                q=d[A[Ai[k]]]
                for c in q:
                    if i==c:
                        print('Yes')
                        quit()
    print('No')






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Ar = sorted(A)
Br = sorted(B)
C = [[0,0]]*n
cnto = 0
for i in range(n):
    C[i]=[A[i],B[i]]
for i in range(n):
    if Br[i] < Ar[i]:
        print('No')
        sys.exit()
    elif [Ar[i],Br[i]] in C:
        cnto += 1
cntx = 0
for i in range(n):
    if B[i]<A[i]:
        cntx += 1
if cntx-cnto > n-1:
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
import numpy as np
import heapq

INF = 10 ** 9 + 2

def sort_likeB(A, B_idx):
    new_A = A.copy()
    for i in range(len(A)):
        new_A = np.append(new_A, A[B_idx[i]])
    return new_A


def main():
    N = int(input())
    A = np.array([int(c) for c in input().split()])
    B = np.array([int(c) for c in input().split()])
    B_idx = np.argsort(B)
    B = np.sort(B)
    A = sort_likeB(A, B_idx)

    num = INF
    for i in range(N):
        if B[i] >= A[i]:
            num = i
            break
    if num == INF:
        print("No")
        sys.exit()
    
    heap = []
    for i in range(N):
        if i == num:
            continue
        heapq.heappush(heap, A[i])
    
    for i in range(N):
        if i == num:
            continue
        else:
            if B[i] < heapq.heappop(heap):
                print("No")
                sys.exit()
            else:
                continue
    print("Yes")    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

    array_raw_a = np.array(A)
    array_raw_b = np.array(B)
    need_to_exchange = (array_raw_b - array_raw_a) < 0

    array_a = np.array(sorted(A))
    array_b = np.array(sorted(B))

    distances = array_b - array_a

    result = 'Yes'
    if sum(distances < 0) > 0:
        result = 'No'
    elif sum(need_to_exchange) > N - 2:
        result = 'No'
    else:
        not_need_to_exchange = np.where(~need_to_exchange)
        for idx in not_need_to_exchange:
            deleted_a = np.sort(np.delete(array_raw_a, idx))
            deleted_b = np.sort(np.delete(array_raw_b, idx))
            if sum((deleted_b - deleted_a) < 0) > 0:
                result = 'No'

    print(result)


if __name__ == '__main__':
    answer()

Submission status: Wrong Answer

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

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:
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:
# -*- coding: utf-8 -*-
a = int(input())
b = input().split()
c = input().split()

for i in range(a):
    b[i] = int(b[i])
    c[i] = int(c[i])

out = "Yes"

b_sort = sorted(b)
c_sort = sorted(c)

for i in range(a):
    if b_sort[i] > c_sort[i]:
        print(i, b_sort[i], c_sort[i])
        out = "No"
        break



print(out)

Submission status: Wrong Answer

Solution code:
import sys
import math as mp

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')
elif(nm<=len(br)-2):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import bisect
from collections import defaultdict
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_A = sorted(A)
sort_B = sorted(B)
if any(a > b for a, b in zip(sort_A, sort_B)):
    print("No")
    exit()

D = defaultdict(int)
for a in sort_A:
    ind = bisect.bisect_left(sort_B, a)
    D[a] = N-ind

for a, b in zip(A, B):
    if a >= b:
        if D[a] == 0:
            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=[[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],a2[i+1]=a2[i+1],a2[i]
        if a2[i]!=a[i]:
            s="No"
            break
print(s)

    #print(a)
    #print(a2)

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)
print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

As = sorted(A)
Bs = sorted(B)


for i in range(N):
    if As[i]>Bs[i]:
        print("No")
        break
else:
    ALR = []
    l = 0
    r = 0
    for i in range(N):
        while r+1<=N-1 and As[r+1]<=Bs[i]:
            r += 1
        while l+1<=N-1 and As[l]>Bs[i]:
            l += 1
        ALR.append([As[i],Bs[l],Bs[r]])
    AB = [[a,b] for a,b in zip(A,B)]
    AB.sort(key = lambda x:x[0])
    cnt = 0
    for i in range(N):
        if AB[i][0] > AB[i][1]:
            cnt += 1
    if cnt > N-2:
        print("No")
    else:
        cnt2 = 0
        for i in range(N):
            if AB[i][1] > ALR[i][2]:
                cnt2 += 1
        if cnt+abs(cnt-cnt2)>N-2:
            print("No")
        else:
            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:
    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-1):
    if bbl[i] - aal[i+1] >= 0 and bbl[i+1] - aal[i] >= 0:
        print("Yes")
        sys.exit()


if set([(a,b) for a,b in zip(sorted(al), sorted(bl))]) & set([(a,b) for a,b in zip(al,bl)]):
    print("Yes")
    sys.exit()


print("No")