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

Submission status: Wrong Answer

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


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


pairs = {}
for i in range(1, N):
    pairs[A_copy_sorted[i]] = (min(A_copy_sorted[i], B_copy_sorted[i - 1] + 1), B_copy_sorted[i])

pairs[A_copy_sorted[0]] = (A_copy_sorted[0], B_copy_sorted[0])
cnt = 0
for a, b in zip(A, B):
    pl, pr = pairs[a]
    if pl <= b <= pr:
        cnt += 1

if cnt > 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()))
        
#print(a)
#print(b)

plist = []

for i in range(len(a)):
    if(a[i] == b[i]):
        plist.append(i)
        
for i in range(len(plist)-1,-1,-1):
    x = plist[i]
    a.pop(x)
    b.pop(x)
    
a.sort()
b.sort()

an = np.array(a)
bn = np.array(b)

#print(a)
#print(b)

if(len(an) == 0):
    ans = "Yes"
    
elif(len(an) <= n-2):
    ans = "Yes"
else:
    flag = 0
    ans = "Yes"
    for i in range(len(an)):
        if(b[i] > a[i]):
            ans = "No"
            break
    
print(ans)

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]
    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 sys
n = int(input())

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

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
#print(cnt)
a.sort()
b.sort()
for i in range(n):
    if a[i] <= b[i]:
        if i == n - 1:
            if cnt > n-2:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()
    else:
        print('No')
        sys.exit()

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()]
ar = list()
for n in range(N):
    ar.append([A[n],B[n]])
ar = sorted(ar, key=lambda x:x[1])
A = [x[0] for x in ar]
B = [x[1] for x in ar]
calc = max(A) <= max(B)
if not calc:
    print("No")
else:
    count = 0
    meet = 0
    not_meet = 0
    for n in range(N):
        if A[n] <= B[n]:
            meet += 1
        else:
            not_meet += 1
    if meet >= 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()))

reverse = 0
for a,b in zip(A,B):
    if a > b:
        reverse += 1
if reverse > N-2:
    print('No')
    exit()
from collections import defaultdict
from bisect import bisect_right
A.sort()
C = []
for e in B:
    C.append(bisect_right(A,e))
C.sort()
for i,c in enumerate(C):
    if i+1 > c:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

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

a_max = max(a)
a_min = min(a)
b_max = max(b)

inv = 0

for i in range(n):
  if a_max > b_max:
    print('No')
    exit()
    
  if a[i] > b[i] :
    if a_min > b[i]:
      print('No')
      exit()
    else:
      inv += 1
      
if inv <= n-2:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
flag = True
for i in range(n):
  if a[i] > b[i]:
    flag = False
    break
if flag:
  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()))

C = sorted(A)
D = sorted(B)



for i,v in enumerate(C):
    if v > D[i]:
        print('No')
        sys.exit()

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

for i in range(n-2):
    max_a = max(a)
    max_b = max(b)
    if max_b < max_a:
        print('No')
        sys.exit()
    else:
        del a[a.index(max_a)]
        del b[b.index(max_b)]

for i in range(2):
    if a[i] > b[i]:
        print('No')
        sys.exit
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()))

    print('Yes')


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()))
a_sorted = sorted(a)
b.sort()

def count_inversion(sequence):
    count = 0
    for i in range(1,len(sequence),1):
        for j in range(i,len(sequence),1):
            if sequence[i-1] > sequence[j]:
                count += 1
    return count
for i in range(n):
    if a_sorted[i] > b[i]:
        print('No')
        sys.exit()
if count_inversion(a) <= 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()))

A.sort()
B.sort()

import numpy as np

AA = np.array(A)
BB = np.array(B)
CC = BB-AA
C = CC.tolist()

ret = 'Yes'
for i in C:
    if i < 0:
        ret = 'No'
print (ret)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[0]*n; B=[0]*n
    C=[0]*n; D=[0]*n
    for i,a in enumerate(map(int,input().split())):
        A[i]=(a,i)
        C[i]=a
    for i,b in enumerate(map(int,input().split())):
        B[i]=(b,i)
        D[i]=b
    A.sort()
    B.sort()

    if(any(A[i][0]>B[i][0] for i in range(n))):
        print("No")
        return

    if(any(A[i+1][0]<=B[i][0] for i in range(n-1))):
        print("Yes")
        return

    cnt=0
    for i in range(n):
        cnt+=C[i]>=D[i]
    if(cnt==1):
        print("No")


    print("Yes")
resolve()

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()
ans="Yes"
for i in range(n):
    if A[i]>B[i]:
        ans="No"
print(ans)

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




    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(n):
    c.append((a[i],0))
    c.append((b[i],1))
c.sort()
c_a=0
c_b=0
for i in range(2*n):
    #print(c_a,c_b)
    if c[i][1]==0:
        c_a+=1
    else:
        c_b+=1
        if c_a<c_b:
            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()))

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        break
else:
    for a, b in zip(A, B):
        if a <= b:
            print('Yes')
            break
    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)の順に格納
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)

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

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 = 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
    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:
        counter += 1
        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:
n = int(input())
l = [int(x) for x in input().split()]
m = [int(x) for x in input().split()]
l.sort()
m.sort()
p=0
for i in range(0,n):
  if l[i]>m[i]:
    p=1
    print("No")
    break
if p==0:
  print("Yes")

Submission status: Wrong Answer

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

c1 = 0
for i in range(N):
  if A[i] <= B[i]:
    c1 += 1
A.sort()
B.sort()
c2 = 0
for i in range(N):
  if A[i] <= B[i]:
    c2 += 1
if c1 >= 2 and c2 == 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()))
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>1 else "No")

Submission status: Wrong Answer

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

p = sorted(a)
q = sorted(b)
for i in range(n):
    if p[i] > q[i]:
        print("No")
        sys.exit()

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

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

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

for i in range(n):
    if max(a) <= max(b):
        a.remove(max(a))
        b.remove(max(b))
    else:
        print('No')
        break
if len(a) == 0:
    print('Yes')

Submission status: Wrong Answer

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

A.sort()
B.sort()
if all(A[i]<=B[i] for i in range(N)):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

def main():
    global A, B
    z = zip(A, B)
    z = sorted(z, key=itemgetter(0))
    z = sorted(z, key=itemgetter(1))
    A, B = zip(*z)
    A = list(A)
    count = 0
    for i, (a, b) in enumerate(zip(A, B)):
        if a > b:
            min_val = min(A[i:])
            min_idx = A[i:].index(min_val)
            A[min_idx] = a
            A[i] = min_val
            if A[i] > b:
                print('No')
                exit()
            count += 1
    if count > N-2:
        print('No')
        exit()
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    A.sort()
    B.sort()
    ret = all(np.greater_equal(B, A))

    return 'Yes' if ret else 'No'


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

Submission status: Wrong Answer

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

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

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()))
        
#print(a)
#print(b)

plist = []

for i in range(len(a)):
    if(a[i] == b[i]):
        plist.append(i)
        
for i in range(len(plist)-1,-1,-1):
    x = plist[i]
    a.pop(x)
    b.pop(x)
    
a.sort()
b.sort()

an = np.array(a)
bn = np.array(b)

#print(a)
#print(b)

if(len(an) == 0):
    ans = "Yes"
else:
    x = (an >= bn)
    if(sum(x > 0)):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

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()]
flag = False
newA = sorted(a)

for i in range(n):
  if(newA[i] == a[i]):
    flag = True

if(flag == False):
  print("No")
  sys.exit()
    
b.sort()

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

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

Submission status: Wrong Answer

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

A.sort()
B.sort()

for x in range(N):
    if A[x] > B[x]:
        print("No")
        break

    if x == (N - 1):
       print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))

    A.sort()
    B.sort()

    if(any(A[i]>B[i] for i in range(n))):
        print("No")
        return

    if(any(A[i+1]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    if(A[0]<=B[0] and all(A[i]>B[i] for i in range(1,n))):
        print("No")
        return

    print("Yes")
resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for i in range(0, N):
  if A[i] > B[i]:
    cnt += 1
if cnt % 2 == 0:
  if cnt // 2 > N - 2:
    print('No')
    exit()
else:
  if -(-cnt // 2) + 1 > N - 2:
    print('No')
    exit()
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:
def swap(a,b):
    a.sort()
    b.sort()
    f=0
    for k in range(len(a)):
        if a[k]>b[k]:
            f=1
            break
    if f==0:
        return "Yes"
    else:
        return 'No'
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(swap(a,b))

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

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

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
#print(cnt)
a.sort()
b.sort()
for i in range(n):
    if a[i] <= b[i]:
        if i == n - 1:
            if cnt > n-3:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()
    else:
        print('No')
        sys.exit()

Submission status: Wrong Answer

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

sa = sorted(a)
sb = sorted(b)

match = 'Yes'
cnt = 0

for i in range(n):
  if sa[i] > sb[i]:
    match = 'No'

for i in range(n):
  if a[i] <= b[i]:
    cnt += 1
if cnt <= 1:
  match = 'No'

print(match)

Submission status: Wrong Answer

Solution code:
N=int(input())
A1=[int(s) for s in input().split()]
B1=[int(s) for s in input().split()]
A2=[(A1[i],i) for i in range(N)]
B2=[(B1[i],i) for i in range(N)]
A=sorted(A2)
B=sorted(B2)
for i in range(N):
  if B[i][0]<A[i][0]:
    print("No")
    break
else:
  for i in range(N-1):
    if B[i][0]>=A[i+1][0]:
      print("Yes")
      break
  else:
    for i in range(N):
      if A[i][1]==B[i][1]:
        print("Yes")
        break
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort()
b.sort()
for i in range(0,n):
    if (b[i] - a[i]) <0:
        print("No")
        break
else:
    print("Yes")

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
e = [0] * n
f = [0] * n

for i in range(n):
    c[i] = [aa[i], i]
    e[i] = [bb[i], i]

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

#print(d)
#print(f)

check = [0] * n
st = d[0]
#print("d", d)
for i in range(n):
    tmp = f[d[st]]
    check[tmp] = 1
    st = tmp
    #print(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())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
for a,b in zip(sorted(A),sorted(B)):
    if a>b:
        print("No")
        exit()
for a,b in zip(A,B):
    if a>b:
        c+=1
print("Yes" if N-c>=2 else "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()
A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
for i in range(N-1):
    if B[i]>=A[i+1]:
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
kaisu=0
def OK(tup):
    if tup[0] <= tup[1]:
        return True
    else:return False
def trade(i,recipient):
    A=recipient[0]
    for j in range(0,i):
        k=i-j-1
        if k==-1:
            print("No")
            exit()
        tpp=tups[k]
        if OK((A,tpp[1])):
            B=tpp[0]
            tpp[0]=A
            recipient[0]=B
            break
    else:
        print("No")
        exit()


N=int(input())
tups=[[i,j] for i,j in zip([int(thing) for thing in input().split(" ")],[int(thing) for thing in input().split(" ")])]
tups.sort(reverse=True,key=lambda x:x[1])
for i in range(0,N):
    tup=tups[i]
    if OK(tup):
        print("OK")
        pass
    else:
        trade(i,tup)
        kaisu=kaisu+1
        if kaisu > N - 1:
            print("No")
            exit()
print("Yes")

Submission status: Wrong Answer

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

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

A.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()))
flag=[1 for a,b in zip(sorted(A),sorted(B)) if b>=a]
if  len(flag)!=N:
    print("No")
    exit()
A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
for i in range(N-1):
    if B[i]>=A[i+1]:
        print("YES")
        exit()
print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

flag = True
for i, j in zip(sorted(a), sorted(b)):
    if i <= j:
        continue
    else:
        flag = False
        break

print('Yes' if flag else 'No')

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


if can is False:
    print("No")
else:
    a = True
    if n == 2:
        if count > 0:
            print("No")
            a = False

    if n == 3:
        if count > 2:
            print("No")
            a = False

    if a:
        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()))
cnt = 0

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
#print(cnt)
a.sort()
b.sort()
for i in range(n):
    if a[i] <= b[i]:
        if i == n - 1:
            if cnt > n-1:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()
    else:
        print('No')
        sys.exit()

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]] and isA_used[bi[1]]==0:
            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 len(aique)>0 and 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:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
cnt = np.count_nonzero(A>B)

if cnt > (N-2)*2:
    print("No")
elif all(np.sort(A) <= np.sort(B)):
    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 = 0
AA = sorted(A)
BB = sorted(B)
for x in range(N):
  if AA[x] > BB[x]:
    a = 1
if N == 2:
  if A[1] <= B[1] and A[0] <= B[0]:
    a = 0
  else:
    a = 1
if a == 0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
flg = 0
cnt = 0
for i in range(n):
    if al[i]<=bl[i]:
        cnt+=1

if cnt < 2:
    flg=1
    
al.sort()
bl.sort()

for i in range(n):
    if al[i]>bl[i]:
        flg=1

if flg==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()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
s = list(set(a))
d = dict()
for i, x in enumerate(s):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(0)
al = [d[x[0]] for x in l]
cnt = 0
t = al[0]
while t != 0:
    t = al[t]
    cnt += 1
if cnt == n - 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

	flag = False
	i = 0
	for a, b in zip(A, B):
		if a<=b:
			i += 1
			if i >= 2:
				flag = True
				break
	if flag:
		k = sum([a>b for a, b in zip(sorted(A), sorted(B))])
		if k == 0:
			print("Yes")
		else:
			print("No")
	else:
		print("No")

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = input().split()
B = input().split()
A = np.array(A).astype(int)
B = np.array(B).astype(int)
A = np.sort(A)
B = np.sort(B)
diff = B - A
if np.min(diff) < 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

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

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

IA = {}
IB = {}
for i in range(N):
    IA[A[i]] = i
    IB[B[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[AA[i]] == IB[BB[i]]:
                print("Yes")
                break
        else:
            print("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[-1-i],a2[-2-i]=a2[-2-i],a2[-1-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()))

sorted_A = sorted(A,reverse=True)
for i in range(n):
  for j in range(len(sorted_A)):
    if B[i]>=sorted_A[j]:
      sorted_A.remove(sorted_A[j])
      break
  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()))
a.sort()
b.sort()
r=True
for i in range(n):
    if (a[i]>b[i]): r=False
if (r):
    print ("Yes")
else:
    print("No")