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; readline = sys.stdin.readline
from collections import deque
from collections import Counter

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

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

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

no = "No"
yes = "Yes"

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

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

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

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

if count <= N - 2:
    print(yes)
else:
    assert False
    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>10*7:
    if all(map(lambda x:x == 2, B)):
        print('No')
    else:
        print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def init(n):
  for i in range(N+1):
    par[i] = i
    rnk[i] = 0
def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
def unite(x, y):
  x = find(x)
  y = find(y)
  if x == y:
    return
  if (rnk[x] < rnk[y]):
    par[x] = y
  else:
    par[y] = x
    if(rnk[x] == rnk[y]):
      rnk[x] += 1
def same(x, y):
  return find(x) == find(y)

N = I()
a = IL()
b = IL()

par = [0 for i in range(N+1)]
rnk = [0 for i in range(N+1)]
init(N)

adata = []
bdata = []
for i in range(N):
  adata.append([a[i], i])
  bdata.append([b[i], i])
adata.sort()
bdata.sort()
#print(adata)
#print(bdata)

for i in range(N):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  if atmp > btmp:
    print("No")
    exit()

for i in range(N-1):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  #print("---")
  #print(atmp,aID)
  #print(btmp,bID)
  if aID == bID:
      break
  if same(aID, bID):
    break
  else:
    unite(aID, bID)
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import math as mp
from itertools import permutations

def l_i():
    arr = [int(a) for a in input().strip().split(' ')]
    return arr
c=0
nm=0
n=int(input())
ar=l_i()
br=l_i()
for i in range(n):
    if(ar[i]<=br[i]):
        c=c+1
    else:
        nm=nm+1
if(n-2>=nm):
    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()))

count = 0
listNOa = []
listNOb = []
#現在満たしている数を数える
for i in range(n):
    if lista[i] <= listb[i]:
        count += 1
    else:
        listNOa.append(lista[i])
        listNOb.append(listb[i])
#現在満たしている数が1だけならダメ
if count == 1:
    print("No")
    exit()
#最後のコーナ処理
#2箇所以上合ってるとき、その全てを入れ替える必要があるかどうか
count2 = 0
NOb_max = max(listNOb)
for i in range(len(listNOa)):
    if listNOa[i] > NOb_max:
        count2 += 1

if count2 >= count:
    print("No")
    exit()
#ここは必須条件
lista.sort()
listb.sort()
for i in range(n):
    if lista[i] > listb[i]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import copy

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

aa_s = sorted(aa)
bb_s = sorted(bb)

if sum([aa_s[i] > bb_s[i] for i in range(n)]) >= 1:
	print("No")
	sys.exit()

if sum([aa[i] <= bb[i] for i in range(n)]) == 0:
	print("No")
	sys.exit()

ii = [i for i in range(n) if aa[i] <= bb[i]]
for i in ii:
	aa_n = copy.deepcopy(aa)
	bb_n = copy.deepcopy(bb)
	aa_n.sort()
	bb_n.sort()
	if sum([aa_n[i] > bb_n[i] for i in range(n)]) == 0:
		print("Yes")
		sys.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()))


able = 0
nable = 0

for i in range(N):

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

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

A.sort()
B.sort()


for i in range(N):

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

print ("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
A_, B_=sorted(A), sorted(B)
flag=True
for i in range(N):
  if A_[i]>B_[i]:
    flag=False
    break
if not flag:
  print("No")
else:
  flag=False
  for i in range(1, N):
    if A_[i-1]==A[i]:
      flag=True
      break
  if flag:
    print("Yes")
  else:
    C=[(A[i], B[i]) for i in range(N)]
    C.sort(key=lambda x:(x[1], x[0]))
    A=[C[i][0] for i in range(N)]
    A_pos={}
    for i in range(N):
      A_pos[A_[i]]=i
    start=A[0]
    now=A[0]
    cnt=1
    while True:
      now=A[A_pos[now]]
      if now==start:
        break
      cnt+=1
    if cnt==N:
      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()

flg = True
for i in range(N):
    if A[i] > B[i]:
        flg = False
        break

if flg:
    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>100000:
    if all(map(lambda x:x == 2, B)):
        print('No')
    else:
        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
        if (n < min):
            min = n
    return max, min, sum


def checkCirculation(list1, list2):
    diff = []
    for i, e in enumerate(list2):
        diff.append(e - list1[i])

    plus = 0
    minus = 0
    for d in diff:
        if (d == 0):
            return False
        elif (d > 0):
            if (plus == 0):
                plus = d
            if (plus != d):
                return False
        else:
            if (minus == 0):
                minus = d
            if (minus != d):
                return False
    return True

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

if (maxA > maxB or minA > minB or sumA > sumB or checkCirculation(listA, listB)):
    print('No')
else:
    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 = sorted(A, reverse=True)
b = sorted(B, reverse=True)

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

if a[1] > b[0]:
    if A[0] == a[1]:
        print("No")
else:
    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)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

A2 = sorted(A)
B2 = sorted(B)

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

for i in range(N-1):
    if B2[i]>=A2[i+1]:
        print('Yes')
        exit()

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

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    A3[i][0] = bindex


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

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

Submission status: Wrong Answer

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

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

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

detection(a_min,b_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
asort = sorted(a)
bsort = sorted(b)
dic = {}
a2b = {}
b2a = {}
for ai, bi in zip(a, b):
    k = str(ai) + "-" + str(bi)
    dic[k] = 1
f = 1
c = 0
for ai, bi in zip(asort, bsort):
    if ai > bi:
        f= 0
        break
    k = str(ai) + "-" + str(bi)
    if k in dic:
        c += 1
    if ai in a2b:
        a2b[ai].append(bi)
    else:
        a2b[ai] = [bi]
    if bi in b2a:
        b2a[bi].append(ai)
    else:
        b2a[bi] = [ai]


if f:
    for ai, bi in zip(a, b):
        if ai <= bi:
            for aj in b2a[bi]:
                for bj in a2b[ai]:
                    if aj <= bj:
                        c += 1
                        break
    if c:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

INF = 10 ** 9 + 2

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


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

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

        

    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

acnt = 0
bcnt = 0
ok = False
prev = 0
for val, check in merge:
    if check == 0 and prev == 0:
        ok = True
    if check == 0:
        acnt += 1
    else:
        bcnt += 1
        if bcnt > acnt:
            print("No")
            exit()
    prev = check
if ok:
    print("Yes")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if all(map(lambda x:x == 2, B)):
    print('No')
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
s = True

if(xs[0]>ys[0]):
    s = False
c = 0
for i in range(1,n):
    if(s):
        if(xs[0]>ys[0]):
            s=False
            c += 1
    else:
        if(xs[0]<=ys[0]):
            s=True
            c += 1

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

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

Submission status: Wrong Answer

Solution code:

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

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

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 numpy as np

n = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))


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

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

D = B - A

num = sum(D < 0)

if num >= n - 1:
    print('No')
else:
    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)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

A2 = sorted(A)
B2 = sorted(B)

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

for i in range(N-1):
    if B2[i]>=A2[i+1]:
        print('Yes')
        exit()

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

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    A3[i][0] = bindex
    A3[i][0] = aindex 

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()))
import numpy as np
D = list(zip(A,B))
A.sort()
B.sort()
judge = len(B)!=len(set(B))
A = np.array(A)
B = np.array(B)
if (A<=B).sum()!=N:
  print('No')

else:
  if judge:
    print('Yes')
  else:
    C = list(zip(A,B))
    for i in D:
      if i in C:
        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()))
aa=[[a[i],i] for i in range(N)]
bb=[[b[i],i] for i in range(N)]
aa.sort()
bb.sort()


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


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


dicb={}
for i in range(N):
    dicb[bb[i][0]]=i


tmp=1
j=0


while tmp<N-1:
    j=dicb[b[j]]
    if j==0: print("Yes"),sys.exit()
    tmp+=1

print("No")

Submission status: Wrong Answer

Solution code:

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

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

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 numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))

# print(np.count_nonzero(a <= b))
# print(np.count_nonzero(a <= b) < n)
flag = False
if np.count_nonzero(a <= b) < n:
    flag = True

# print(a, b)
a.sort()
b.sort()
# print(a, b)

# print(a <= b)

if flag:
    print("Yes" if np.all(a <= b) else "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = -co
for i in range(n):
    k = bb[i][2]

    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        count += 1



if count >= n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
c = sorted(a)
d = sorted(b)
for i in range(n):
    if c[i] > d[i]:
        print('No')
        quit()
#print(c,d)
f = defaultdict(int)
for i in range(n):
    f[a[i]] = b[i]
lst = []
cnt = 0
for i in range(n):
    if f[c[i]] != d[i]:
        cnt += 1
if math.ceil(cnt/2) > n-2:
    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()))


able = 0
nable = 0

for i in range(N):

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

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

A.sort()
B.sort()


for i in range(N):

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

print ("Yes")

Submission status: Wrong Answer

Solution code:
import sys

N=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[[a[i],i] for i in range(N)]
bb=[[b[i],i] for i in range(N)]
aa.sort()
bb.sort()


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


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


dicb={}
for i in range(N):
    dicb[bb[i][0]]=i


tmp=1
j=0
print(dicb)

while tmp<N-1:
    j=dicb[b[j]]
    if j==0: print("Yes"),sys.exit()
    tmp+=1
    
print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

orderA = {}
orderB = {}

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    orderA[i] = k
    orderB[j] = k

AtoI = {a : i for i, a in enumerate(orderA.values())}
BtoI = {b : i for i, b in enumerate(orderB.values())}

path = 0
visited = [False] * N
for i, a in enumerate(orderA.keys()):
    if visited[i]:
        continue
    visited[i] = True
    length = 0
    now = i
    while True:
        visited[now] = True
        length += 1
        now = BtoI[now]
        now = AtoI[now]
        if now == i:
            break

    path = max(path, length)

if path <= N - 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(' ')))
saa = sorted(aa)
sbb = sorted(bb)

hoge = [a > b for a, b in zip(saa, sbb)]
# (1,2)
# (2,1) NG
# (1,2,3)
# (2,1,3) OK
# (1,2,3)
# (2,3,1) NG
memo = dict()
for a, b in zip(saa, sbb):
    memo[(a,b)] = memo.get((a,b), 0) + 1
valid = False
for a, b in zip(aa, bb):
    valid = valid or (a,b) in memo
if any(hoge) or not valid:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    count = heap_sort(A)
    B = sorted(map(int, input().split()))
    if count > n-2:
        print('No')
    else:
        for i in range(n):
            if B[i] - A[i] < 0:
                print('No')
        else:
            print('Yes')


def heap_sort(array):
    count = 0
    i = 0
    n = len(array)

    while(i < n):
        # ヒープを構成
        count = upheap(array, i, count)
        i += 1

    while(i > 1):
        # ヒープから最大値を取り出し
        i -= 1
        tmp = array[0]
        array[0] = array[i]
        array[i] = tmp

        # ヒープの再構成
        downheap(array, i-1, count)
    return count

# array[n]をヒープ構成部(0～n-1)の最適な位置へ移動
def upheap(array, n,count):
    while n != 0:
        parent = int((n - 1) / 2)
        if array[n] > array[parent]:
            # 親より大きな値の場合親子の値を交換
            tmp = array[n]
            array[n] = array[parent]
            array[parent] = tmp
            n = parent
            count += 1
        
        else:
            break
    return count

# ルート[0]をヒープ(0～n)の最適な位置へ移動
def downheap(array, n,count):
    if n == 0: return
    parent = 0
    while True:
        child = 2 * parent + 1 # array[n]の子要素
        if child > n: break
        if (child < n) and array[child] < array[child + 1]:
            child += 1
        if array[parent] < array[child]: # 子要素より小さい場合スワップ
            tmp = array[child]
            array[child] = array[parent]
            array[parent] = tmp
            parent = child; # 交換後のインデックスを保持
            count += 1
        
        else:
            break
    return count


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

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 selectionsort(a,n):
  counter = 0
  for i in range(n-1):
    idx = None
    mi = a[i]
    flag = False
    for x in reversed(range(i,n)):
      if mi > a[x]:
        idx = x
        mi = a[x]
        counter+=1
        flag = True
    if flag:
      a[i],a[idx] = a[idx],a[i]
  return a, counter
 
len = int(input())
a = sorted([int(i) for i in input().split(" ")])
b = [int(i) for i in input().split(" ")]
b, counter = selectionsort(b,len)

Flag = True

if counter >= len-2:
  print("No")
  Flag = False

else:
  for i in range(len):
    if a[i] > b[i]:
      print("No")
      Flag = False
      break
      

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

orderA = {}
orderB = {}

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    orderA[i] = k
    orderB[j] = k

AtoI = {a : i for i, a in enumerate(orderA.values())}
BtoI = {b : i for i, b in enumerate(orderB.values())}

path = 0
visited = [False] * N
for i, a in enumerate(orderA.keys()):
    if visited[i]:
        continue
    visited[i] = True
    length = 0
    now = i
    while True:
        visited[now] = True
        length += 1
        now = BtoI[now]
        now = AtoI[now]
        if now == i:
            break

    path = max(path, length)

if path <= 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()))
C=sorted([[a,i+1] for i,a in enumerate(A)])
D=sorted([[b,i+1] for i,b in enumerate(B)])
E=[]
f=True
for i in range(n):
  if C[i][0]>D[i][0]:
    print("No")
    exit()
  elif i!=0:
    if C[i][0]<=D[i-1][0]:
      f=False
  if C[i][1]>D[i][1]:
    E.append(C[i][1]-D[i][1])
  elif C[i][1]<D[i][1]:
    E.append(n+C[i][1]-D[i][1])
print("No" if f and len(set(E))==1 and len(E)==n else "Yes")

Submission status: Wrong Answer

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

from queue import PriorityQueue

def readInts():
  return [int(s) for s in input().split(" ")]

def solve(N, A, B):
  zipped = sorted(zip(A, B), reverse=True)
  pq = PriorityQueue()
  for i, (a, b) in enumerate(zipped):
    pq.put((-1 * b, i))

  c = 0
  t = 0
  for i in range(N):
    if zipped[i][0] > zipped[i][1]:
      mb, k = pq.get()
      while k < i:
        mb, k = pq.get()
      b = -1 * mb
      if zipped[i][0] <= b:
        pq.put((-1 * zipped[i][1], k))
        zipped[k] = (zipped[k][0], zipped[i][1])
        c += 1
      else:
        return False
    else:
      t += 1
  return (c <= N - 2) or t > 0

def main():
  N = readInts()[0]
  A = readInts()
  B = readInts()
  if solve(N, A, B):
    print('Yes')
  else:
    print('No')

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

    aa = a[1:]
    aa.append(a[0])
    a.sort()
    b.sort()

    for i in range(n):
        if a[i] <= b[i]:
            pass
        else:
            print('No')
            exit()

    if a == aa:
        print('No')
        exit()

    print('Yes')

Submission status: Wrong Answer

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

import sys
n = int(input())

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

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

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

            
for a,b in zip(al,bl):
    if b-a >= 0:
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

heapA = []
heapB = []
for i in range(N):
    heappush(heapA, A[i])
    heappush(heapB, B[i])    
    
ans = 'Yes'
for i in range(N):
    a = heappop(heapA)
    b = heappop(heapB)    
    if a > b:
        ans = 'No'
        break
        
print(ans)