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

# 必要
c = sorted(a)
d = sorted(b)
for i in range(n):
    if c[i]>d[i]:
        print('No')
        exit()

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

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

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



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()))
y = 0
A1 = sorted(A)
B1 = sorted(B)

for x in range(N):
    if A1[x] > B1[x]:
        print("No")
        break
    if A[x] != A1[x] or B[x] != B1[x]:
        y = y + 1
    if y > ((N - 2) * 2):
        print("No")
        break
    if x == (N - 1):
       print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    ia = []
    ib = []
    for i, (a, b) in enumerate(zip(aa, bb)):
        ia.append([a, i])
        ib.append([b, i])
    ia.sort()
    ib.sort()
    #print(ia)
    #print(ib)
    flag = False
    for sj in range(n):
        a0, ai0 = ia[sj]
        b0, bi0 = ib[sj]
        if a0 > b0:
            print("No")
            exit()
        if flag: continue
        for j in range(sj, n):
            a1, ai1 = ia[j]
            b1, bi1 = ib[j]
            if a1 > b0: break
            if ai1 == bi0 or ai0==bi1:
                flag = True
                break
    print("Yes") if flag else print("No")

main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

def solve() :
    sA, tB = zip(*sorted(zip(A, B)))
    sB = sorted(B)
    
    for i in range(N) :
        if sA[i] > sB[i] :
            return 'No'
            
    for i in range(1, N) :
        if sA[i] <= sB[i-1] :
            return 'Yes'
            
    tB = [bisect_left(sB, tB[i]) for i in range(N)]
    pos = [0] * N
    for k, v in enumerate(tB) :
        pos[v] = k
    # print(tB)
    # print(pos)
    
    count = 0
    for i in range(N) :
        if pos[i] == i :
            continue
        j = pos[i]
        # print(i, j, pos[i], pos[j])
        pos[i], pos[j] = pos[j], pos[i]
        count += 1
        # print(pos)
    # print('swap', count)
    if count <= N - 2 :
        return 'Yes'
    else :
        return 'No'
    
print(solve())

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()
        
for a,b in zip(al,bl):
    if b -a >= 0:
        print("No")
        sys.exit()
        
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()]
sub=[]


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

if min(a)-min(b)>0:
    print("No")
    sys.exit()
else:
    for i in range(n-2):
        a_max_index = a.index(max(a))
        b_max_index = b.index(max(b))
        a[a_max_index],a[b_max_index]=a[b_max_index],a[a_max_index]
        del a[b_max_index]
        del b[b_max_index]

detection(a,b)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
n = int(input())
A = np.array(list(map(int,input().split())))
B = np.array(list(map(int,input().split())))
sa = np.sort(A)
sb = np.sort(B)
if (np.any(sb-sa<0)):
  print("No")
  sys.exit(0)
if ((sum((B-A) < 0)) < n-1):
    print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))

def maxminsumNum(list):
    max = 0
    min = 1000000000
    sum = 0
    for n in list:
        sum += n
        if (max < n):
            max = n
            continue
        if (n < min):
            min = n
            continue
    return max, min, sum

maxA, minA, sumA = maxminsumNum(listA)
maxB, minB, sumB = maxminsumNum(listB)

if (maxA > maxB | minA > minB | sumA > sumB):
    print('No')

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
if cnt > n - 2:
    print("No")
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('Yes')
        sys.exit()

Submission status: Wrong Answer

Solution code:
n,A,B=open(0);*A,=map(int,A.split());*B,=map(int,B.split())
j=[a>b for a,b in zip(A,B)].count(True)
A.sort();B.sort()
print("YNeos"[(j>int(n)-2)|any(a>b for a,b in zip(A,B))::2])

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

else :
    count = 0
    ng = 0
    for i in range(len(a)):
        if (a[i] > b[i]):
            fl = 0
            for j in range(len(b)):
                if (a[i] <= b[j] and a[j] <= b[i]):
                    a[i],a[j] = a[j],a[i]
                    count = count + 1
                    fl = 1
                    break
            if (fl == 0):
                print ('No')
                break

    #for k in range(len(a)):
    #    if (a[i] > b[i]):
    #        print ('No')
    

    if (n-2 >= count and fl == 1):
        print ('Yes')
    elif (n-2 < count):
        print ('No')

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split(" "))),dtype="int64")
B=np.array(list(map(int,input().split(" "))),dtype="int64")
A=np.sort(A)
B=np.sort(B)
D=True
for a,b in zip(A,B):
	if a>b:
		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()))
a.sort()
b.sort()
p = [0]*n
j = 0
for i in range(n):
    while b[j]<a[i]:
        j+=1
        if j==n-1:
            break
    if b[j]<a[i]:
        break
    p[j]+=1
count = 0
for i in range(n):
    if p[i]==0:
        count -=1
        if count <0:
            print("No")
            exit()
    else:
        count += p[i]
        count -=1
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)
ABs=list(zip(As,Bs))

ans="Yes"
for ab in ABs:
    if ab[0]>ab[1]:
        ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
cnt=0
for i in range(n):
    if al[i]<=bl[i]:
        cnt+=1
asl=sorted(al)
bsl=sorted(bl)
for i in range(n):
    if asl[i]>bsl[i]:
        print('No')
        break
else:
    if cnt>=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_s = a.copy()
b_s = b.copy()

a_s.sort()
b_s.sort()

c = 0
cc = 0

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

if n > 2 and c == n-1:
    print('No')
    cc = 1

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

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
las=sorted(la)
lbs=sorted(lb)
for i in range(n):
    if las[i]>lbs[i]:
        print("No")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n or len(sb)!=n:
    print("Yes")
    exit()
lc=sorted([[lb[i],la[i]] for i in range(n)])
a=[0]*n
for num,i in enumerate(lc):
    a[num]=bisect.bisect_left(las,i[1])
used = [ False ] * n
cnt = 0
for i in range(n):
    j = i
    used[j] = True
    while a[j] != j:
        j = a[j]
        if used[j]:
            break
        used[j] = True
        cnt += 1
if cnt<n-1:
    print("No")
else:print("Yes")

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
import bisect

def main():
    N=int(input())
    A=[int(x) for x in input().split()]
    B=[int(x) for x in input().split()]

    NA=np.array(A)
    NB=np.array(B)

    SNA=np.sort(NA)
    SNB=np.sort(NB)

    if np.any(SNB-SNA<0):
        return 'No'


    
    argsNB=np.argsort(NB)
    sSNA=NA[argsNB]


    
    AL=SNA.tolist()
    AL2=sSNA.tolist()
    BL=SNB.tolist()



    SE=set((j,k) for j,k in zip(AL,AL2))

    for a1,a2 in zip(AL,AL2):
        if (a2,a1) in SE:
            return 'Yes'

    return 'No'
        
    
        
        
        
    
    
    

    

print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    la = rli()
    lb = rli()
    ll = []
    pb = []
    for i in range(n):
        ll.append([la[i], lb[i]])
    ll.sort()
    for i in range(n):
        pb.append([ll[i][1], i])
    pb.sort()
    pc = [0 for _ in range(n)]
    for i in range(n):
        pc[pb[i][1]] = i
    # print(pb)
    # print(pc)

    la.sort()
    lb.sort()
    for i in range(n):
        if la[i] > lb[i]:
            print("No")
            return

    cnt = 0
    # print(ll)
    for i in range(n):
        j = pc[i]
        if i == j:
            continue
        while i != j:
            if ll[i][0] != ll[j][0] and ll[i][1] != ll[j][1]:
                cnt += 1
            ll[i][1], ll[j][1] = ll[j][1], ll[i][1]
            pc[i], pc[j] = pc[j], pc[i]
            # print(i, j, ll[i], ll[j])
            j = pc[i]
    # print(ll)
    if cnt <= n-2:
        print("Yes")
    else:
        print("No")
    

    # print('Yes')


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

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

cnt = 0
for a, b in zip(A, B):
    if a > b:
        cnt += 1

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

pair = {}
for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        break
    else:
        pair[(a, b)] = 0
else:
    for a, b in zip(A, B):
        if (a, b) in pair:
            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()))
AB=zip(sorted(A),sorted(B))
for i,j in AB:
    if i<=j:continue
    else:print("No");exit()

cnt=0
for i in range(n):
    if A[i]>B[i]:cnt +=1

print("Yes" if n-2>=cnt else "No")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
N = int(stdin.readline().rstrip())
_A = stdin.readline().rstrip().split()
_B = stdin.readline().rstrip().split()

A = [int(s) for s in _A]
B = [int(s) for s in _B]
array = copy.copy(A)

n = len(array)
count = 0
tes = True

for i in range(n-1):
    for j in range(n-1, i, -1):
        if array[j] < array[j-1]:
            tmp = array[j]
            array[j] = array[j-1]
            array[j - 1] = tmp
            count += 1
            if (count > (N - 2)):
                tes = False
                print('No')
                break
    if (count > (N - 2)):
        break

A.sort()
B.sort()

if (tes):
    for n in range(N):
        if (A[n] > B[n]):
            print('No')
            tes = False
            break

if (tes):
    print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

numA = np.array(A)
A.sort()
B.sort()
An = np.array(A)
Bn = np.array(B)
if(np.min(Bn-An) < 0):
  print("No")

else:
  order = numA.argsort()[::-1]
  cnt = 0
  for i in order:
    if(A[i] > B[i]):
      cnt += 1
  if(cnt > N-2):
    print("No")
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = sorted(list(map(int, input().split(' '))))
bb = sorted(list(map(int, input().split(' '))))
hoge = [a > b for a, b in zip(aa, bb)]
if any(hoge):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def solve(n, a_list, b_list):
    a_list_s = sorted(a_list)
    b_list_s = sorted(b_list)

    # check 1
    for i in range(n):
        if a_list_s[i] > b_list_s[i]:
            return "No"

    # check 2
    for i in range(n - 1):
        if a_list_s[i + 1] <= b_list_s[i]:
            return "Yes"

    # check 3
    # do it
    # arg sort
    a_list_s_arg = dict()
    b_list_s_org = dict()
    res_list = [0] * n
    for j in range(n):
        a_list_s_arg[a_list_s[j]] = j
    for k in range(n):
        b_list_s_org[b_list[k]] = k
    for i in range(n):
        j = a_list_s_arg[a_list[i]]
        k = b_list_s_org[b_list_s[j]]
        res_list[i] = k

    for i in range(n):
        if res_list[i] == i:
            return "Yes"
        res_list[i], res_list[res_list[i]] = res_list[res_list[i]], res_list[i]

    return "No"


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    res = solve(n, a_list, b_list)
    print(res)


def test():
    assert solve(3, [1, 3, 2], [1, 2, 3]) == "Yes"
    assert solve(3, [1, 2, 3], [2, 2, 2]) == "No"
    assert solve(6, [3, 1, 2, 6, 3, 4], [2, 2, 8, 3, 4, 3]) == "Yes"


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

Submission status: Wrong Answer

Solution code:
n,A,B=open(0);*A,=map(int,A.split());*B,=map(int,B.split())
j=[a>b for a,b in zip(A,B)].count(True)
A.sort();B.sort()
print("YNeos"[(j>1)|any(a>b for a,b in zip(A,B))::2])

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

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:
    i = 0
    j = 0
    k = 0
    X = [0] * N
    Y = [0] * N
    for j in range(N):
        while i < N - 1 and AA[i+1] <= BB[j]:
            i += 1
        X[j] = i
        Y[j] = k
        if i == j: k = i + 1
    
    for i in range(N):
        if IA[AA[Y[i]]] <=  IB[BB[i]] <= IA[AA[X[i]]]:
            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()
dekiru=1
for i in range(n):
	if a[i]>b[i]:
		dekiru=0
		break
if dekiru==1:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
import sys
N  = int(input())
As = np.array(list(map(int, input().split(' '))))
Bs = np.array(list(map(int, input().split(' '))))
if As.max() > Bs.max():
    print('No')
    sys.exit()
if np.all(As[0] > Bs[:-1]):
    print('No')
    sys.exit()
if np.all(As > Bs).sum() > N-2:
    print('No')
    sys.exit()
As.sort()
Bs.sort()
if np.any(As > Bs):
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np
yes, no = "Yes", "No"
n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
sb = np.sort(b)
sa = np.sort(a)
sbi = np.argsort(b)
if np.any(sb < sa):
    print(no)
    exit(0)
# if np.any(sb[:-1] >= sa[1:]):
#     print(yes)
#     exit(0)

count = 1
i = 0
while True:
    j = sbi[i]
    if j == 0:
        break
    i = j
    count += 1
if count == n:
    print(no)
else:
    print(yes)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def even(N,A,sA): # 置換の偶奇性を数える
    d={}
    for i,Ai in enumerate(A):
        d[Ai]=i # 重複ある場合に注意
    cnt=0
    for i in range(N):
        if A[i]!=sA[i]:
            A[i],A[d[sA[i]]]=A[d[sA[i]]],A[i]
            cnt+=1
    return cnt%2==0

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

f1=True;f2=True;f3=True;f4=True
sA=sorted(A[:])
sB=sorted(B[:])
for i in range(N):
    if sA[i]>sB[i]:
        f1=False
        break
if f1:
    CA=Counter(A);CB=Counter(B)
    vA=CA.values();vB=CB.values()
    if max(vA)>=2 or max(vB)>=2:
        f2=True
    else:
        f2=False

if not f2:
    tA=even(N,A,sA);tB=even(N,B,sB)
    if tA!=tB:
        f3=True
    else:
        f3=False

if not f3:
    if sA[-1]<=sB[-2] and sA[-2]<=sB[-1]:
        f4=True
    else:
        f4=False

if not f1:
    f=False
elif f2:
    f=True
elif f3:
    f=True
elif f4:
    f=True
else:
    f=False

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

Submission status: Wrong Answer

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

A=np.sort(A)
B=np.sort(B)
D=True
for a,b in zip(A,B):
	if a>b:
		D=False
		break

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

Submission status: Wrong Answer

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

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

acnt = 0
bcnt = 0
ok = False
for val, check in merge:
    if check == 0:
        acnt += 1
    else:
        bcnt += 1
        if bcnt > acnt:
            print("No")
            exit()
        if bcnt < acnt:
            ok = True
if ok:
    print("Yes")
else:
    for aa, bb in zip(a, b):
        if aa == bb:
            print("Yes")
            exit()
    print("No")

Submission status: Wrong Answer

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

def calc(A, B):
  for i in range(len(A)):
    if B[i] < A[i]:
      return 'No'
  return 'Yes'
  
print(calc(A, B))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = list(list(zip(A,B)))
AB.sort(key=lambda x: x[1])
As = sorted(A)
Bs = sorted(B)

for i in range(n):
    if AB[i][0] <= AB[i][1]:
        del AB[i]
        break

As = list()
Bs = list()
for i, j in AB:
    As.append(i)
    Bs.append(j)

As.sort()
Bs.sort()

flag = True
for i in range(n-1):
    if As[i] > Bs[i]:
        flag = False



if flag:
    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()))


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

Submission status: Wrong Answer

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

valid = True
c = 0
d = 0
for i in range(n):
    if(xs[i]<=ys[i]):
        c += 1
    else:
        d += 1

if(c==1 or d==1 or c==0):
    valid = False
    print("No")

if(valid):
    xs.sort()
    ys.sort()

    for i in range(n):
        if (xs[i]>ys[i]):
            valid = False
            print("No")
            break

if(valid):
    print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
las=sorted(la)
lbs=sorted(lb)
for i in range(n):
    if las[i]>lbs[i]:
        print("Yes")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n or len(sb)!=n:
    print("No")
    exit()
lc=sorted([[lb[i],la[i]] for i in range(n)])
a=[0]*n
for num,i in enumerate(lc):
    a[num]=bisect.bisect_left(las,i[1])
used = [ False ] * n
cnt = 0
for i in range(n):
    j = i
    used[j] = True
    while a[j] != j:
        j = a[j]
        if used[j]:
            break
        used[j] = True
        cnt += 1
if cnt<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()))
A.sort()
answer = "Yes"
for i in range(0,N):
  if A[i] < B[i]:
    answer = "No"
print(answer)

Submission status: Wrong Answer

Solution code:


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

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

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

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

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

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

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


uf = UnionFind(N)
for A,B in zip(As_ind,Bs_ind):
    if A[0] > B[0]:
        print("No")
        exit()
    uf.union(A[1],B[1])
    

d_ans = defaultdict(int)
for i in range(N):
    root = uf.find(i)
    d_ans[root] += 1
if len(d_ans) >= 2:
    print("Yes")
else:
    print("No")

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) or min(B) < min(A):
    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:
n = int(input())
xs = [int(i) for i in input().split()]
ys = [int(i) for i in input().split()]

valid = True
c = 0
d = 0
for i in range(n):
    if(xs[i]<=ys[i]):
        c += 1
    else:
        d += 1

if(c==1 or d==1):
    valid = False
    print("No")

if(valid):
    xs.sort()
    ys.sort()

    for i in range(n):
        if (xs[i]>ys[i]):
            valid = False
            print("No")
            break

if(valid):
    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()))
ans = 0
ans2 = 0

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

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

for i in range(n):
  if a[i] > b[i]:
    print("No")
    ans += 1
    break
    
if ans2 > math.ceil((n-2)/2) and ans == 0:
  print("No")
elif ans == 0:
  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()))


def check(lis1, lis2):
  diff = [0 if ai<=bi else 1 for ai,bi in zip(lis1,lis2)]
  tmp = sum(diff)
  lis1 = sorted(lis1)
  lis2 = sorted(lis2)
  diff = [0 if ai<=bi else 1 for ai,bi in zip(lis1,lis2)]
  if sum(diff)==0 and tmp<len(lis1)-1:
    return "Yes"
  else:
    return "No"

diff = [0 if ai<=bi else 1 for ai,bi in zip(a,b)]
tmp = sum(diff)
a_res = [ai for ai,bi in zip(a,b) if ai>bi]
b_res = [bi for ai,bi in zip(a,b) if ai>bi]

#print(a_res)
#print(b_res)

if check(a_res, b_res)=="Yes":
  print("Yes")
  sys.exit(0)

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

diff = [0 if ai<=bi else 1 for ai,bi in zip(a,b)]

if sum(diff)==0 and tmp<n-1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
las=sorted(la)
lbs=sorted(lb)
for i in range(n):
    if las[i]>lbs[i]:
        print("No")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n or len(sb)!=n:
    print("No")
    exit()
lc=sorted([[lb[i],la[i]] for i in range(n)])
a=[0]*n
for num,i in enumerate(lc):
    a[num]=bisect.bisect_left(las,i[1])
used = [ False ] * n
cnt = 0
for i in range(n):
    j = i
    used[j] = True
    while a[j] != j:
        j = a[j]
        if used[j]:
            break
        used[j] = True
        cnt += 1
if cnt<n-1:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls, b_ls = zip(*sorted([(a, b) for a, b in zip(a_ls, b_ls)], key=lambda x:x[1]))
a_ls = list(a_ls)
cnt = 0
last = n - 1
flg = True
for i, (a, b) in enumerate(zip(a_ls, b_ls)):
    if b < a:
        last = n - 1
        while b < a_ls[last] or a > b_ls[last]:
            last -= 1
            if last == -1:
                flg = False
                break
        tmp = a_ls[i]
        a_ls[i] = a_ls[last]
        a_ls[last] = a_ls[i]
        cnt += 1
        if cnt > n - 2:
            flg = False
            break
    if not flg:
        break
if flg:
    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()))
cnt = 0

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
if cnt > n - 2:
    print("No")
a.sort()
b.sort()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

def countOvers(n, aList, bList):
  count = 0
  for i in range(n):
    if (aList[i] > bList[i]):
      count += 1
  return count

def compareSorted(n, aList, bList):
  aSorted = sorted(aList)
  bSorted = sorted(bList)
  result = True
  for i in range(n):
    if (aSorted[i] > bSorted[i]):
      result = False
      break
  return result

if countOvers(n, aList, bList) > n - 2:
  print('No')
elif not compareSorted(n, aList, bList):
  print('No')
else:
  print('Yes')

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