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:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=sorted(A)
B=sorted(B)
if B[0]<A[0] or B[N-1]<A[N-1]:
  print('No')
  exit()
for i in range(N):
  if A[i]>B[i]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[[i,j] for i,j in zip(a,b)]
a.sort()
b.sort()
c.sort()
for i,j in zip(a,b):
    if i>j:
        print("No")
        exit()
d=0        
for i in range(n):
   if b[i]==c[i][1]:
       d+=1
print("Yes" if d>0 else "No")

Submission status: Wrong Answer

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

arr1 = []
arr2 = []
sum = 0
ans = 1

aa = sorted(List[0])
bb = sorted(List[1])

for i in range(len(List[0])):
  a = List[0][i]
  b = List[1][i]
  
  if a > b :
    arr1.append(a)
    arr2.append(b)
  
  c = aa[i]
  d = bb[i]
  
  if c > d:
    ans = 0
    
length = len(arr1)


print("No")

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)
ans = 'Yes'
for i in range(len(a)):
  if b[i] - a[i] < 0:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
def is_possible_build_swap(n, a, b):
    a.sort()
    b.sort()
    for i in range(0,n):
        if a[i] > b[i]:
            return False
    return True


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    print("Yes" if is_possible_build_swap(n, a, b) else "No")


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

    Asub = sorted(A)
    Bsub = sorted(B)
    for i in range(N):
        if Asub[i] > Bsub[i]:
            print("No")
            break
    else:print("Yes")



    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

arr1 = []
arr2 = []
sum = 0
ans = 1

aa = sorted(List[0])
bb = sorted(List[1])

for i in range(len(List[0])):
  a = List[0][i]
  b = List[1][i]
  
  if a > b :
    arr1.append(a)
    arr2.append(b)
  
  c = aa[i]
  d = bb[i]
  
  if c > d:
    ans = 0
    
length = len(arr1)

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    A.sort()
    B2 = sorted(B)
    cnt = 0

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

    for i in range(N):
        if B[i] != B2[i]:
            cnt += 1

    if cnt > N - 1:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
alis = [int(i) for i in input().split()]
blis = [int(i) for i in input().split()]


def ab (alis,blis):
    for i in range(n):
        if alis[i] > blis[i]:
            return 0
    return 1

def cd (alis,blis):
    c = 0
    for i in range(n):
        if alis[i] <= blis[i]:
            c += 1
    if c >= 1:
        return 1
    else:
        return 0
ans1 = cd (alis,blis)
alis.sort()
blis.sort()
ans2 = ab(alis,blis)
if ans1 and ans2 :
    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()))
c=[[i,j] for i,j in zip(a,b)]
a.sort()
b.sort()
for i,j in zip(a,b):
    if i>j:
        print("No")
        exit()
d=0        
for i in range(n):
   if b[i]==c[i][1]:
       d+=1
print("Yes" if d>0 else "No")

Submission status: Wrong Answer

Solution code:
n=int(input())

a1=list(map(int,input().split()))
b=list(map(int,input().split()))
a2=sorted(a1)
b.sort()

for i in range(n):
    if b[i]<a2[i]:
        s="No"
        break
else:
    s="Yes"

for i in range(n-1):
    a2[i],a2[i+1]=a2[i+1],a2[i]
if a1==a2:
    s="No"

print(s)

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)
count=0

for i in range(N):
    if  a[i]<=b[i]:
        count+=1
    else:
        pass
if count==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()))
if n == 2:
    if a[0] <= b[0] and a[1] <= b[1]:
        print('Yes')
    else:
        print('No')
    exit()
    
cnt = sum([1 if a[i] > b[i] else 0 for i in range(n)])
if cnt >= n - 1:
    print('No')
    exit()
else:
    a.sort()
    b.sort()
    for i in range(n):
        if a[i] > b[i]:
            print('No')
            exit()
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A, B = [], []
for i, a in enumerate(map(int,input().split())):
  A.append([a,i])
for i, b in enumerate(map(int,input().split())):
  B.append([b,i])
A.sort()
B.sort()

reps = set()
for a, b in zip(A,B):
  if a[0] > b[0]:
    print('No')
    exit()
  if a[1] != b[1]:
    reps.add(tuple(sorted([a[1],b[1]])))
if len(reps) <= N-2: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
import bisect

n=int(input())
alist = [int(i) for i in input().split()] 
blist = [int(i) for i in input().split()] 
clist=[]
for i in range(n):
    clist.append([blist[i], alist[i]])

clist=sorted(clist)
aalist=[]
bblist=[]
for i in range(n):
    aalist.append(clist[i][1])
    bblist.append(clist[i][0])
swit=0
now=0
dame=0
life=n
#print(aalist,bblist)
while swit==0:
    if aalist[now]<=bblist[now]:
        now+=1
    else:
        pos=bisect.bisect_left(bblist, aalist[now])
        saisho=aalist[now]
        mark=0
        ok=0
        for i in range(n-pos):
            if aalist[pos+i]<saisho:
                saisho=aalist[pos+i]
                mark=pos+i
                ok=1
            if aalist[pos+i]<=bblist[now]:
                save=aalist[now]
                aalist[now]=aalist[pos+i]
                aalist[pos+i]=save
                life-=1
                now+=1
                ok=2
                break
        if ok==0:
            swit=1
            dame=1
        elif ok==1:
            save=aalist[now]
            aalist[now]=aalist[mark]
            aalist[mark]=save
            life-=1
    if life<0:
        swit=1
        dame=1
    if now==n:
        swit=1

#print(aalist,bblist, life)
if dame==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

arr1 = []
arr2 = []
sum = 0
ans = 1

aa = sorted(List[0])
bb = sorted(List[1])

for i in range(len(List[0])):
  a = List[0][i]
  b = List[1][i]
  
  if a > b :
    arr1.append(a)
    arr2.append(b)
  
  c = aa[i]
  d = bb[i]
  
  if c > d:
    ans = 0
    
length = len(arr1)

if ans == 0:
  print("No")
elif (N-2) < length:
  print("No")
else :
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

def find_smaller_in_alist(index, b):
    for i in range(n):
        if a_list[i] <= b and a_list[index] <= b_list[i]:
            return i
        if i == n-1:
            return -1
counter = 0

for i in range(n):
    if a_list[i] <= b_list[i]:
        pass
    elif counter == n-2:
        print("No")
        break
    else:
        index = find_smaller_in_alist(i, b_list[i])
        if index == -1:
            print("No")
            break
        else:
            a_list[i], a_list[index] = a_list[index], a_list[i]
    if i == n-1:
        print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
	_ = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))

	k = sum([a>b for a, b in zip(sorted(A), sorted(B))])
	if k == 0:
		print("Yes")
	else:
		print("No")
	
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()))

if(set(a) == set(b)):
  count = 0
  for i in range(n):
    if(a[i]>b[i]):
      count += 1
  if(count > n//2):
    print("No")
else:
  a.sort()
  b.sort()
  if(min(a)>min(b)):
    print("No")
  else:
    for i in range(n):
      if(a[i] <= b[i]):
        if(i==n-1):
          print("Yes")
          break
        continue
      else:
        print("No")
        break

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


DIV = 998244353

def main():
    N = iRaw()
    As = isRaw()
    Bs = isRaw()
    AIs = [[a,idx] for idx,a in enumerate(As)]
    BIs = [[a, idx] for idx, a in enumerate(Bs)]
    
    BIs.sort()
    aique = []
    isA_used = [0]*len(As) 
    
    for ai in AIs:
        heappush(aique,[ai[0],-Bs[ai[1]],ai[1]])
    
    nSwap = 0
    for bi in BIs:
        if bi[0]>=As[bi[1]]:
            isA_used[bi[1]]=1
        else:
            if bi[0]<aique[0][0]:
                return "No"
            else:
                isA_used[aique[0][2]] = 1
                nSwap +=1
                heappop(aique)
        while isA_used[aique[0][2]]==1:
            heappop(aique)
    if nSwap>N-2:
        return "No"
    return "Yes"

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())
dat_a = list(map(int, input().split()))
dat_b = list(map(int, input().split()))
dat_aa = []
dat_bb = []
for i in range(n):
    dat_aa.append(dat_a[i])
    dat_bb.append(dat_b[i])


count = 0
for i in range(n):
    if dat_a[i] > dat_b[i]:
        count += 1

can = True
dat_aa.sort()
dat_bb.sort()
for i in range(n):
    if dat_aa[i] > dat_bb[i]:
        can = False
a = True
if can is False:
    print("No")
else:
    if n == 2:
        if dat_a[0] > dat_b[0] or dat_a[1] > dat_b[1]:
            print("No")
            a = False

    if n == 3:
        if dat_a[1] > dat_b[1]:
            if dat_a[0] > dat_b[0]:
                if dat_a[3] > dat_b[3]:
                    print("No")
                    a = False
    if a:
        print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    flag = 0
    for i in range(n):
        if a[i] > b[i]:
            flag += 1
    if flag >= n - 1:
        return "No"
    a.sort()
    b.sort()
    for i in range(n):
        if a[i] > b[i]:
            return "No"
    return "Yes"


print(main())

Submission status: Wrong Answer

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

count1 = 0
count2 = 0

A_new = sorted(A)
B_new = sorted(B)

for i in range(N):
    if B[i] >= A[i]:
        count1 += 1
        
    if B_new[i] >= A_new[i]:
        count2 += 1

if count1 > 1 and count2 == N:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

if sum([aa[i] <= bb[i] for i in range(n)]) >= 1:
	aa.sort()
	bb.sort()
	if sum([aa[i] > bb[i] for i in range(n)]) == 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()))

a.sort(reverse=True)
b.sort(reverse=True)

flag = 0
for i in range(n):
    if a[i] > b[i]:
        flag = 1
        break


if flag ==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()))
c = [[b[i],a[i]] for i in range(n)]
c.sort()
a = [c[i][1] for i in range(n) ]
b = [c[i][0] for i in range(n) ]
#print(a)
#print(b)
cnt = n - 2
for i in range(n):
    if a[i] > b[i]:
        if cnt < 0:
            print("No")
            exit()
        tmpa = a[i:]
        disa = []
        for j in range(len(a[i:])):
            disa.append(a[i+j]-b[i])
        #print(a[i],disa)
        k = disa.index(min(disa))+i
        a[i],a[k] = a[k],a[i]
        cnt -= 1
        if a[i] > b[i]:
            print("No")
            exit()
#print(a)
#print(b)
print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ABs = []
for i in range(N):
  A, B = As[i], Bs[i]
  ABs.append((A, B))
ABs.sort()
As2 = [A for A, B in ABs]
Bs2 = [B for A, B in ABs]
#print(As2)
#print(Bs2)
Bs3 = sorted(Bs2)
ok = True
for i in range(N):
  if Bs3[i] < As2[i]:
    ok = False
    break
if not ok:
  print("No")
  exit()
Is = sorted(range(N), key=lambda i: Bs2[i])
#print(Is)
ok = False
for i in range(N):
  if Is[i] == i:
    ok = True
    break
if ok:
  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()))

a1 = sorted(a)
b1 = sorted(b)

ans = 'Yes'
for i in range(n):
    if a1[i] > b1[i]:
        ans = 'No'
        break

if ans == 'Yes':
    cnt = 0
    for i in range(n):
        if a[i] > b[i]:
            cnt += 1

    if cnt >= n-2:
        ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
for i in range(len(A)):
  if A[i] > B[i]:
    print("No")
    break
else:
  print("Yes")

Submission status: Wrong Answer

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

a.sort()
b.sort()
D=True
for i,n in zip(a,b):
	if i>n:
		D=False
		break

if D:
	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()))
flag=[1 for a,b in zip(sorted(A),sorted(B)) if b>=a]
if  len(flag)!=N:
    print("No")
    exit()
flag=[1 for a,b in zip(A,B) if b>=a]

if  len(flag)<=1:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
alis = [int(i) for i in input().split()]
blis = [int(i) for i in input().split()]


def ab (alis,blis):
    for i in range(n):
        if alis[i] > blis[i]:
            return 0
    return 1

def cd (alis,blis):
    c = 0
    for i in range(n):
        if alis[i] <= blis[i]:
            c += 1
    if c >= 2:
        return 1
    else:
        return 0
ans1 = cd (alis,blis)
alis.sort()
blis.sort()
ans2 = ab(alis,blis)
if ans1 and ans2 :
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

aa.sort()
bb.sort()
if sum([aa[i] > bb[i] for i in range(n)]) >= 1:
	print("No")
else:
	if sum([aa[i] <= bb[i] for i in range(n)]) >= 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()))

count = 0
for i in range(n):
    if a[i] <= b[i]:
        count += 1
if count <= 1:
    flag = False
else:
    a.sort()
    b.sort()
    flag = True
    for i in range(n):
        if a[i] > b[i]:
            flag = False
            break
if flag == True:
    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()))
ans = 'Yes'
a.sort()
b.sort()
i=0
while (i<N):
    if a[i]>b[i]:
        ans = 'No'
        break
    i+=1
print(ans)

Submission status: Wrong Answer

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

a=[]
b=[]
count=0

for i in range(N):
    a.append(min(A))
    b.append(min(B))
    if  a[i]<=b[i]:
        count+=1
    else:
        pass
if count==N:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_list.sort()
b_list.sort()
count = 0

if max(a_list) > max(b_list):
    print('No')
else:
    for i in range (n-1):
        if a_list[i] > b_list[i]:
            count = 1
            break

    if count == 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()
s = 0

for i in range (0,N):
  if A[i] > B[i]:
    s = s + 1
if (B[0] != B[N-1]) and (B[0] == B[N-2]):
  if s > N-3:
    print("No")
  else:
    print("Yes")
if B[0] == B[N-1]:
  if s > N-4:
    print("No")
  else:
    print("Yes")

else:
  if s > 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 = 0
AA = sorted(A)
BB = sorted(B)
for x in range(N):
  if AA[x] > BB[x]:
    a = 1
if a == 0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
flag=[1 for a,b in zip(sorted(A),sorted(B)) if b>=a]
if  len(flag)!=N:
    print("NO")
    exit()
flag=[1 for a,b in zip(A,B) if b>=a]

if  len(flag)<=1:
    print("NO")
    exit()
print("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)の順に格納
from operator import itemgetter
def index_sort(A):
    return sorted(enumerate(A),key=itemgetter(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(N-2)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp

if A[A3[1][0]]<=B[B3[1][0]] and A[A3[1][1]]<=B[B3[1][1]]:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#%%
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

a = aa.copy()
b = bb.copy()

a.sort()
b.sort()

flag = False
for i in range(n):
    if a[i] <= b[i]:
        pass
    else:
        flag = True



c = [0] * n
d = [0] * n
for i in range(n):
    c[i] = [aa[i], i]

c.sort()
for i in range(n):
    d[i] = c[i][1]

#print(d)

check = [0] * n
st = d[0]
for i in range(n):
    tmp = d[st]
    check[tmp] = 1
    st = tmp

#print(check)
flag2 = True
for i in range(n):
    if check[i] == 0:
        flag2 = False
    else:
        flag2 = True

if flag or flag2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
ABs = []
for i in range(N):
  A, B = As[i], Bs[i]
  ABs.append((A, B))
ABs.sort()
As = [A for A, B in ABs]
Bs = [B for A, B in ABs]
#print(As)
#print(Bs)
Is = sorted(range(N), key=lambda i: Bs[i])
#print(Is)
ok = False
for i in range(N):
  if Is[i] == i:
    ok = True
    break
if ok:
  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()))
A.sort()
B.sort()
A_mat = np.array(A)
B_mat = np.array(B)
C = B_mat - A_mat
if np.all(C >= 0):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

a = [int(i) for i in a]
b = [int(i) for i in b]

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

if c+2 > n:
    print('No')
    exit()

a.sort()
b.sort()

for i in range(n):
    if a[i] <= b[i]:
        continue
    else:
        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()))
ans = 0

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AS = sorted(A)
BS = sorted(B)
isPossible = True
for i in range(N):
    if AS[i] > BS[i]:
        isPossible = False
        break
if isPossible:
    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()))
A = sorted(A)
B = sorted(B)

flg = 1
for i in range(N):
	if not A[i] <= B[i]:
		flg = 0
		break
if flg:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())
a = map(int, input().split())
b = map(int, input().split())
qa = []
qb = []
for x in a:
  heapq.heappush(qa, x)
for x in b:
  heapq.heappush(qb, x)
for i in range(n):
  xa = heapq.heappop(qa)
  xb = heapq.heappop(qb)
  if xa > xb:
    print('No')
    break
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
import bisect
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(int)

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

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

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

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

#インデックス付きソート
#(index,value)の順に格納
from operator import itemgetter
def index_sort(A):
    return sorted(enumerate(A),key=itemgetter(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 B[i]>=A[i+1]:
        print('Yes')
        exit()

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

for i in range(N-2)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp

if A[A3[1][0]]<=B[B3[1][0]] and A[A3[1][1]]<=B[B3[1][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()))

a.sort()
b.sort()

c = 0

for i in range(n):
    if a[i] > b[i]:
        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()))

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

BI = [(b, i) for i, b in enumerate(B)]
BI.sort()
bToI = {}

for i, (b, j) in enumerate(BI):
    bToI[j] = i

cnt = 0
for i, a in enumerate(A):
    if bToI[i] != i:
        cnt += 1

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

Submission status: Wrong Answer

Solution code:
def main():
    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]:
            return "No"
    return "Yes"


print(main())

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()
for i in range(n):
    if b[i]<a[i]:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a_list.sort()
b_list.sort()
count = 0

if max(a_list) > max(b_list):
    print('No')
else:
    for i in range (n-1):
        if a_list[i] > b_list[i]:
            count += 1

    if count > n-2:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

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

inv = 0

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


if inv < 1:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
def swap(a,b):
    return 'Yes'
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(swap(a,b))

Submission status: Wrong Answer

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

a.sort()
b.sort()

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

if ans >= n-2:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

for i in range(n):
  if(a[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()))
a.sort()
b.sort()
for i,j in zip(a,b):
    if i>j:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split(' ')])
b = sorted([int(x) for x in input().split(' ')])

for i in range(n) :
    if(a[i] > b[i]) :
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

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

AA = sorted(A)
BB = sorted(B)

for i in range(N):
  if AA[i] > BB[i]:
    print('No')
    break
else:
  print('Yes')

Submission status: Wrong Answer

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

A.sort()
B.sort()
s = 0

for i in range (0,N):
  if A[i] > B[i]:
    s = s + 1
if B[0] != B[N-1]:
  if s > N-2:
    print("No")
  else:
    print("Yes")
else:
  if s > N-3:
    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.sort()
B.sort()

for i,v in enumerate(A):
    if v > B[i]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys

def main():
    sys.stdin.readline()
    A = [int(x) for x in sys.stdin.readline().split()]
    B = [int(x) for x in sys.stdin.readline().split()]
    n = 0
    for i in range(len(A)):
        if A[i] <= B[i]:
            continue

        flg = False
        for j in range(len(A)):
            if j == i:
                continue
            if A[j] <= B[i] and A[i] <= B[j]:
                tmp = A[j]
                A[j] = A[i]
                A[i] = tmp
                n += 1
                flg = True
                break
        if not flg:
            return False
    return n <= len(A) - 2


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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
B = input().split()
preANS = 0

for i in range(N):
    A[i] = int(A[i])

for i in range(N):
    B[i] = int(B[i])

for i in range(N):
    if A[i] > B[i]:
        for j in range(i,N):
            if A[j] < B[i]:
                A[i], A[j] = A[j], A[i]
                preANS += 1

if preANS < N-2:
    print("Yes")
else:
    print("No")