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 = [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[AA[i]] = i
    IB[BB[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 Y[IB[B[i]]] <= IA[A[i]] <= X[IB[B[i]]]:
            print("Yes")
            break #################
    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:
    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:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a.sort()
b.sort()

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

Submission status: Wrong Answer

Solution code:
# -*- 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[1] == a[0] and B[1] != b[0]:
        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()))
aa=a
bb=b
a.sort()
b.sort()
dekiru=1
onaji=0
issho=0
for i in range(n):
	if a[i]==aa[i]:
		onaji=1
if onaji==1:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("Yes")
	else:
		print("No")
		
else:print("Yes")
	# for i in range(n):
		# if aa[i]==bb[i]:
			# issho=1
			# memo=i
			# break
	# if issho==1:
		# a.remove(aa[memo])
		# b.remove(bb[memo])
		# for i in range(n):
			# if a[i]>b[i]:
				# dekiru=0
				# break
			# if dekiru==1:
				# print("Yes")
			# else:
				# print("No")
	# else:
		# print("No")

Submission status: Wrong Answer

Solution code:
import copy

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:
    r = 10**9
    check = []
    for i in range(n):
        if 0 <= B[i] - A[i] < r:
            r = B[i] - A[i]
            m = i
    for i in range(n):
        if B[i] - A[i] == m:
            check.append(m)
    for idx in check:
        C = copy.deepcopy(A)
        D = copy.deepcopy(B)
        C.pop(idx)
        D.pop(idx)
        for c, d in zip(sorted(C), sorted(D)):
            if c > d:
                break
        else:
            print('Yes')
            break
    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()))
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:
  if a.index(A[lst[0]])==b.index(B[lst[0]]):
    print('Yes')
  else:
    print('No')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())

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

count = 0

flag = True

for x, y in zip(a, b):
  if x < y:
    count += 1

if count > n-2:
  flag = False

sa = sorted(a, reverse=True)
sb = sorted(b, reverse=True)

for x, y in zip(sa, sb):
  if x > y:
    flag = False
    break


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

Submission status: Wrong Answer

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

cmb = [(b_[i],a_[i]) for i in range(n)]
cmb.sort()
a_.sort()
b_.sort()
for i in range(n):
    if a_[i]>b_[i]:
        print("No")
        sys.exit()
a = [cmb[i][1] for i in range(n)]
b = [cmb[i][0] for i in range(n)]
cnt = 0
for i in range(n):
    if a[i]>b[i]:
        cnt += 1
if cnt>=n-1:
    print("No")
    sys.exit()
"""
i = n-1
j = n-1
while i>0:
    if a[i]<=b[i]:
        i-=1
    else:
        while b[j]<a[i]:
            j-=1
            if j<0:
                print("No")
                sys.exit()
            i-=1
"""            
print("Yes")

Submission status: Wrong Answer

Solution code:
class SegmentTree():

    def __init__(self, size, initial=-1):
        node_size = 1
        while node_size < size:
            node_size <<= 1
        self.st = [initial] * ((node_size << 1) - 1)
        self.size = node_size

    def update(self, target, new_value):
        target += self.size - 1
        self.st[target] = new_value
        while target > 0:
            parent = (target - 1) >> 1
            if self.st[parent] > self.st[target]:
                self.st[parent] = self.st[target]
                target = parent
            else:
                break

    def query(self, a, b):
        # [a,b)の最大値を求める。
        return self._query(a, b, 0, 0, self.size)

    def _query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return (float('inf'), float('inf'))
        if a <= l and r <= b:
            return self.st[k]
        vl = self._query(a, b, (k << 1) + 1, l, (l + r) >> 1)
        vr = self._query(a, b, (k << 1) + 2, (l + r) >> 1, r)
        return min(vl, vr)


def solve(n, a, b):
    if n == 2:
        if a[0] <= b[0] and a[1] <= b[1]:
            return True
        else:
            return False
    cnt = sum([1 if a[i] > b[i] else 0 for i in range(n)])
    if cnt >= n - 1:
        return False

    a_ = sorted(a)
    for i in range(n):
        if a_[i] > b[i]:
            return False

    st = SegmentTree(len(a), (float('inf'), float('inf')))
    for i in range(n):
        st.update(i, (a[i], i))
    cnt = 0
    for i in range(n):
        if a[i] > b[i]:
            v, j = st.query(i, n + 1)
            if v > b[i]:
                return False
            a[j] = a[i]
            st.update(j, (a[i], j))
            a[i] = v
            cnt += 1
    return cnt <= n-2


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [(b[i], a[i]) for i in range(n)]
    c.sort()
    a = [c[i][1] for i in range(n)]
    b = [c[i][0] for i in range(n)]
    if solve(n, a, b):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
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
for z in range(N-2):
  A[A.index(AA[N-z-1])],A[B.index(BB[N-z-1])] = A[B.index(BB[N-z-1])],A[A.index(AA[N-z-1])]
for x in range(N):
  if A[x] > B[x]:
    a = 1                                             
if a == 0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=a
bb=b
a.sort()
b.sort()
dekiru=1
onaji=0
issho=0
for i in range(n):
	if a[i]==aa[i]:
		onaji=1
if onaji==1:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("Yes")
	else:
		print("No")
		
else:
	for i in range(n):
		if aa[i]==bb[i]:
			issho=1
			memo=i
			break
	if issho==1:
		a.remove(aa[memo])
		b.remove(bb[memo])
		for i in range(n):
			if a[i]>b[i]:
				dekiru=0
				break
			if dekiru==1:
				print("Yes")
			else:
				print("No")
	else:
		print("No")

Submission status: Wrong Answer

Solution code:
import sys

N=int(input())

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

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=0
j=0
while tmp<N-2:
    j=dicb[b[j][0]]
    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()))
AB=list(zip(A,B))

As=sorted(A)
Bs=sorted(B)
ABs=list(zip(As,Bs))

ans="Yes"
for i,ab in enumerate(ABs):
    if ab[0]>ab[1]:
        ans="No"

count=0
for ab in AB:
    if ab[0]>ab[1]:
        count+=1
if count > N-2:
    ans="No"

print(ans)

Submission status: Wrong Answer

Solution code:
class SegmentTree():

    def __init__(self, size, initial=-1):
        node_size = 1
        while node_size < size:
            node_size <<= 1
        self.st = [initial] * ((node_size << 1) - 1)
        self.size = node_size

    def update(self, target, new_value):
        target += self.size - 1
        self.st[target] = new_value
        while target > 0:
            parent = (target - 1) >> 1
            if self.st[parent] > self.st[target]:
                self.st[parent] = self.st[target]
                target = parent
            else:
                break

    def query(self, a, b):
        # [a,b)の最大値を求める。
        return self._query(a, b, 0, 0, self.size)

    def _query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return (float('inf'), float('inf'))
        if a <= l and r <= b:
            return self.st[k]
        vl = self._query(a, b, (k << 1) + 1, l, (l + r) >> 1)
        vr = self._query(a, b, (k << 1) + 2, (l + r) >> 1, r)
        return min(vl, vr)


def solve(n, a, b):
    if n == 2:
        if a[0] <= b[0] and a[1] <= b[1]:
            return True
        else:
            return False
    cnt = sum([1 if a[i] > b[i] else 0 for i in range(n)])
    if cnt >= n - 1:
        return False

    a_ = sorted(a)
    for i in range(n):
        if a_[i] > b[i]:
            return False

    st = SegmentTree(len(a), (float('inf'), float('inf')))
    for i in range(n):
        st.update(i, (a[i], i))
    cnt = 0
    for i in range(n):
        if a[i] > b[i]:
            v, j = st.query(i, n + 1)
            if v > b[i]:
                return False
            a[j] = a[i]
            st.update(j, (a[i], j))
            a[i] = v
            cnt += 1
    print(cnt)
    return cnt <= n-2


def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = [(b[i], a[i]) for i in range(n)]
    c.sort()
    a = [c[i][1] for i in range(n)]
    b = [c[i][0] for i in range(n)]
    if solve(n, a, b):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

    distances = array_b - array_a

    result = 'Yes'
    if need_to_exchange > N - 2:
        result = 'No'
    elif sum(distances < 0) > 0:
        result = 'No'

    print(result)


if __name__ == '__main__':
    answer()

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

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
BA = sorted([(b, a) for a, b in zip(A, B)])
A = [a for b, a in BA]
B = [b for b, a in BA]


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


def f(x, y):
    if x[1] < y[1]:
        return x
    else:
        return y


cnt = 0
ST = SegmentTree(list(enumerate(A)), f=f, ti=(-1, 10**10))
for i in range(N):
    now = ST.query(i, i + 1)
    if now[1] > B[i]:
        cand = ST.query(i + 1, N)
        if cnt < N - 1 and cand[1] <= B[i]:
            cnt += 1
            ST.update(cand[0], (cand[0], now[1]))
            ST.update(now[0], (now[0], cand[1]))
        else:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    n = input()
    aa = map(int, raw_input().split())
    bb = map(int, raw_input().split())
    if any(a > b for a, b in zip(sorted(aa), sorted(bb))):
        print 'No'
        return
    if sum(a <= b for a, b in zip(aa, bb)) >= 2:
        print 'Yes'
    else:
        print 'No'


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

Submission status: Wrong Answer

Solution code:
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 > n-2 and ans == 0 and n > 100000:
  print("No")
elif ans == 0:
  print("Yes")

Submission status: Wrong Answer

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

def sellect_sort(A, B):
    cnt = 0
    for (A_ind, A_ele), (B_ind, B_ele) in zip(enumerate(A),enumerate(B)):
        A_min_ind = min(range(A_ind, len(A)), key=A.__getitem__)
        B_min_ind = min(range(B_ind, len(B)), key=B.__getitem__)
        if A_min_ind != B_min_ind and B[A_min_ind] != B[B_min_ind]:
            cnt += 1
        A[A_ind], A[A_min_ind] = A[A_min_ind], A_ele
        B[B_ind], B[B_min_ind] = B[B_min_ind], B_ele
        
    #print(cnt)
    #print(A)
    #print(B)
    return A, B, cnt


def f():
    A_sort, B_sort, cnt = sellect_sort(A, B)
    if cnt > N-2:
        return 'No'
    for a, b in zip(A_sort, B_sort):
        if a > b:
            return 'No'
        
    return 'Yes'



print(f())

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 = []

for i in range(n):
    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 = 0
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:
import sys
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
counter = 0
for i in range(n):
    if B[i]<A[i]:
        counter += 1
if counter >= n-1:
    print('No')
    sys.exit()
else:
    Ar = sorted(A)
    Br = sorted(B)
    for i in range(n):
        if Br[i] < Ar[i]:
            print('No')
            sys.exit()
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()))

    # 既に条件満たしている時
    if(all(A[i]<=B[i] for i in range(n))):
        print("Yes")
        return

    C=[0]*n
    D=[0]*n
    for i,a in enumerate(A):
        C[i]=(a,i)
    C.sort()
    for i in range(n):
        j=C[i][1]
        D[i]=B[j]

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

    # DがAの回転のときダメ
    idx=-1
    for i in range(n):
        if(A[i]>D[i]):
            idx=i
            break
    if(idx==-1):
        print("Yes")
        return
    if(D[idx:]+D[:idx]==B):
        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()))
C=sorted([[a,i] for i,a in enumerate(A)])
D=sorted([[b,i] for i,b in enumerate(B)])
E=[]
for i in range(n):
  if C[i][0]>D[i][0]:
    print("No")
    exit()
  elif 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 len(set(E))==1 and len(E)==n else "Yes")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

if max(A)>max(B):
  print('No')
else:
  sorted_A = sorted(A)
  for i in range(n):
    if min(A)>B[i]:
      print('No')
      exit()
    idx=bisect.bisect_left(sorted_A,B[i])-1
    sorted_A.remove(sorted_A[idx])
  print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
A.sort()
B.sort()
s = 0
 
for i in range (0,N):
  if A[i] > B[i]:
    s = s + 1
if ((B[N-2] != B[N-1]) and (B[0] == B[N-2])) or ((B[0] != B[1]) and (B[1] == B[N-1])):
  if s > N-4:
    print("No")
  else:
    print("Yes")
if B[0] == B[N-1]:
  if s > N-6:
    print("No")
  else:
    print("Yes")
 
else:
  if s > N-2:
    print("No")
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

flag = 0
for i in range(n):
    if a[i]>b[i]:
        flag = 1
        break
if flag == 1:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

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

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()

ab = []

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

ab = sorted(ab, key=lambda x:(x[1],x[0]))


if len(set(aa)) < n:
    print('Yes')
    exit()

for i in range(n):
    if aa[i] == ab[i][0]:
        print('Yes')
        exit()

from collections import defaultdict
d = defaultdict(int)

for i in range(n):
    d[aa[i]] += i

abd = [0]*n

for i in range(n):
    abd[i] = d[ab[i][0]]

for i in range(n):
    if abd[abd[i]] == 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=[[a[i],i] for i in range(N)]
b=[[b[i],i] for i in range(N)]
aa,bb=sorted(a),sorted(b)

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=0
j=0
while tmp<N-1:
    j=dicb[b[j][0]]
    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()))

b_min = 10**18
a_max = 0
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if b[i] < b_min:
            a_max = a[i]
            b_min = b[i]
            ind = i
        elif b[i] == b_min and a[i] > a_max:
            a_max = a[i]
            ind = i

if ind == -1:
    print("No")
    exit()
a = sorted(a[0:ind] + a[ind+1:])
b = sorted(b[0:ind] + b[ind+1:])

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = 0
a = 0
b = 0
k = 0
for i  in range(0, N - 2):         
  if A[i] > B[i]:
    C = A[i]
    A[i] = B[i]
    B[i] = C
    break
    
for j in range(N- 1, 0 ,-1):
  a += 10**j * A[k]
  b += 10**j * B[k]
  k += 1
  
if a <= b:
  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):


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

if (maxA > maxB or minA > minB or sumA > sumB):
    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()
for i in range(len(a)):
    if a[i] > b[i]:
        print("No")
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))

Alist.sort()
Blist.sort()

check = True
for i in range(N):
    if Alist[i] > Blist[i]:
        check = False
        break

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]*n
b=[]*n
a=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))
aso=sorted(a)
bso=sorted(b)
ans=True
for i in range(n):
    if aso[i]>bso[i]:ans=False
cnt=0
for i in range(n):
    if a[i]!=aso[i]:cnt+=1
if cnt>n-2:ans=False

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A_list = np.array(list(map(int, input().split())))
B_list = np.array(list(map(int, input().split())))
diff = B_list - A_list >= 0
diff_num = np.sum(diff)
if diff_num > 1:
    A_list.sort()
    B_list.sort()
    if np.sum(A_list - B_list > 0) > 0:
        print("No")
    else:
        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(a, b)
a.sort()
b.sort()
# print(a, b)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
Alist = np.array(list(map(int, input().split())))
Blist = np.array(list(map(int, input().split())))
hikaku = np.sort(Alist) <= np.sort(Blist)
if (False not in hikaku) and np.sum(hikaku) >= 2:
    print("Yes")

else:
    print("No")

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[AA[i]] = i
    IB[BB[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 Y[IB[B[i]]] <= i <= X[IB[B[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()
if any((A[i] > B[i]) for i in range(N)):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort(reverse = True)
B.sort(reverse = True)
for i in range(N):
  if A[i] > B[i]:
    print("No");exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
def main():
  N=int(input())
  A=list(map(int,input().split()))
  B=list(map(int,input().split()))
  tmp={}
  for i in range(N):
    if not A[i] in tmp.keys():
      tmp[A[i]]=[]
    tmp[A[i]].append(B[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 
 # print(tmp)
  for i in range(N):
    if B[i] in tmp[A[i]]:
      print("Yes")
      return
  print("No")
      
main()

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[1] == a[0]:
        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_s = sorted(a)
b_s = sorted(b)
ans = 'Yes'
for i in range(n):
    if a_s[i]>b_s[i]:
        ans = 'No'
        break
print(ans)

Submission status: Wrong Answer

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

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

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

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()
    
for i in range(1,n):
    if aa[i] <= bb[i-1]:
        print('Yes')
        exit()

dg = 10**10

ab = []
for i in range(n):
    ab.append(b[i]*dg+a[i])
ab.sort()

a = []
for e in ab:
    a.append(e%dg)


idx = {}
for i in range(n):
    k = bisect.bisect_left(aa,a[i])
    idx[k] = i


for i in range(n-1):
    if a[i] == aa[i]:
        print('Yes')
        exit()
    a[idx[i]] = a[i]

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

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

Submission status: Wrong Answer

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

c = a.copy()

a.sort()
b.sort()

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

for i in range(n):
    if a[i]==c[i]:
        print("Yes")
        exit()
        
for i in range(n-1):
    if a[i]<=b[i+1] and a[i+1]<=b[i]:
        print("Yes")
        break
else:
    print("No")