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()))
l = sorted(list(zip(b, a)))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
    
bound = a[n - 1] + 1
for i in range(1, n):
  if a[i] <= b[i - 1]:
    bound = a[i - 1]
    break
 
p = 0
for i, (x, y) in enumerate(l):
  if x >= y:
    if y >= a[i] or i == 0 or y > bound:
      print('Yes')
      exit()
 
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = sorted(list(zip(b, a)))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
 
p = 0
for i, (x, y) in enumerate(l):
  if x >= y >= a[i]:
    print('Yes')
    exit()
 
print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [0] * N
for i in range(N):
	if sorted(A)[i] > sorted(B)[i]:
		print("No")
		exit()
	if A[i] > B[i]:
		C[i] = 1
	B[i] -= A[i]
if sum(C) > N - 2 or sum(B) < 0:
	print("No")
	exit()
print("Yes")

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

# Check bi >= ai is possible
a_s = sorted(a)
b_s = sorted(b)
for i, (aa, bb) in enumerate(zip(a_s, b_s)):
    if aa > bb:
        print("No")
        exit()

# Check there are pair such that ai <= ai+1 <= bi
for ai1, bi in zip(a_s[1:], b_s):
    if ai1 <= bi:
        print("Yes")
        exit()

# get ab's cyclic permutation
a_idx = []
for i, aa in enumerate(a):
    a_idx.append((aa, i))
a_idx.sort()

visited = [0] * n
cycle = 0
for i in range(n):
    curr = i
    if visited[curr] == 1:
        continue
    cycle += 1
    while visited[curr] == 0:
        visited[curr] = 1
        curr = a_idx[curr][1]
if cycle > 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ail=[(i,a) for i,a in enumerate(al)]
bil=[(i,b) for i,b in enumerate(bl)]
ail=sorted(ail,key=lambda x:x[1])
bil=sorted(bil,key=lambda x:x[1])
if not all([ail[i][1]<=bil[i][1] for i in range(n)]):
    print('No')
    exit()
if any([ail[i][0]==bil[i][0] for i in range(n)]):
    print('Yes')
    exit()
c=[(ail[i][0],bil[i][0]) for i in range(n)]
c=sorted(c)
idx=0
for _ in range(n-2):
    idx=c[idx][1]
    if idx==0:
        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()))
ba = sorted((y, x) for x, y in zip(a, b))
a = [x for y, x in ba]
b = [y for y, x in ba]

# print(a)
# print(b) 

ap = sorted((x, i) for i, x in enumerate(a))

# print(ap) 
if any(ap[i][0] > b[i] for i in range(n)):
    print('No')
    exit()
if any(ap[i + 1][0] <= b[i] for i in range(n - 1)):
    print('Yes')
    exit()

rep = [ap[i][1] for i in range(n)]
p = 0
c = 0
# print(rep)
print(['No', 'Yes'][c != n])
# print(n)
# print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ba = sorted((y, x) for x, y in zip(a, b))
a = [x for y, x in ba]
b = [y for y, x in ba]


ap = sorted((x, i) for i, x in enumerate(a))

print(ap) 
if any(ap[i][0] > b[i] for i in range(n)):
    print('No')
    exit()
if any(ap[i + 1][0] <= b[i] for i in range(n - 1)):
    print('Yes')
    exit()

rep = [ap[i][1] for i in range(n)]
p = 0
c = 0
print(['No', 'Yes'][rep[n-1] != 0])

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ail=[(i,a) for i,a in enumerate(al)]
bil=[(i,b) for i,b in enumerate(bl)]
ail=sorted(ail,key=lambda x:x[1])
bil=sorted(bil,key=lambda x:x[1])
if not all([ail[i][1]<=bil[i][1] for i in range(n)]):
    print('No')
    exit()
if any([ail[i][0]==bil[i][0] for i in range(n)]):
    print('Yes')
    exit()
c=[(ail[i][0],bil[i][0]) for i in range(n)]
c=sorted(c)
idx=0
for _ in range(n-1):
    idx=c[idx][1]
    if idx==0:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ail=[(i,a) for i,a in enumerate(al)]
bil=[(i,b) for i,b in enumerate(bl)]
ail=sorted(ail,key=lambda x:x[1])
bil=sorted(bil,key=lambda x:x[1])
if not all([ail[i][1]<=bil[i][1] for i in range(n)]):
    print('No')
    exit()
if any([ail[i][0]==bil[i][0] for i in range(n)]):
    print('Yes')
    exit()
c=[(ail[i][0],bil[i][0]) for i in range(n)]
c=sorted(c)
print(c)
idx=0
for _ in range(n-1):
    idx=c[idx][1]
    if idx==0:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ail=[[i,a] for i,a in enumerate(al)]
bil=[[i,b] for i,b in enumerate(bl)]
ail=sorted(ail,key=lambda x:x[1])
bil=sorted(bil,key=lambda x:x[1])
if not all([ail[i][1]<=bil[i][1] for i in range(n)]):
    print('No')
    exit()
if any([ail[i][0]==bil[i][0] for i in range(n)]):
    print('Yes')
    exit()
if any([ail[i+1][1]<=bil[i][1] for i in range(n-1)]):
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]

asort = sorted(a)
bsort = sorted(b)
flg = ''


for i in range(n) :
    if(asort[i] > bsort[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j] <= b[j]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

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

p = 0
for i, (x, y) in enumerate(l):
  if x < y and y >= a[i]:
    print('Yes')
    exit()

print('No')

Submission status: Wrong Answer

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

flg = ''


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

if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j+1] <= b[j]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

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

p = 0
for x, y in l:
  if x < y and y >= a[i]:
    print('Yes')
    exit()

print('No')

Submission status: Wrong Answer

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

flg = ''


for i in range(n) :
    if(asort[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

cnt = 0
if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j+1] < b[j]) :
            cnt += 1
            if(cnt > 1) :
                flg = 'Yes'
                break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

flg = ''


for i in range(n) :
    if(asort[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

cnt = 0
if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j+1] <= b[j]) :
            cnt += 1
            if(cnt > 1) :
                flg = 'Yes'
                break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

flg = ''


for i in range(n) :
    if(asort[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'


if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j+1] <= b[j]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

flg = ''


for i in range(n) :
    if(asort[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'


if (flg == 'Yes') :
    for j in range(n-1) :
        print(a[j+1])
        print(b[j])
        if(a[j+1] <= b[j]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

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

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

p = 0
for x, y in l:
  # print(x, y)
  if x < y:
    continue
  while p < n and a[p] <= x:
    p += 1
  if p == n or y <= a[p]:
    print('Yes')
    exit()

Submission status: Wrong Answer

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

flg = ''


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

if (flg == 'Yes') :
    for j in range(n-1) :
        if(a[j+1] < b[j]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

Solution code:
N = int(input())
ax = list(map(int,input().split()))
bx = list(map(int,input().split()))

ax_ = (sorted(ax))
bx_ = (sorted(bx))
rx = [a > b for a,b in zip(ax_,bx_)]
if any(rx):
    print('No')
    exit()

ax = sorted([(i, a) for i, a in enumerate(ax)], key=lambda x:x[1])
#print(ax)
#exit()
ix = [i for i,a in enumerate(ax)]

p = c = 0
while True:
    c += 1
    p = ix[p]
    if p == 0:
        break
print(['No', 'Yes'][c != N])

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())

    list11 = [int(x) for x in input().split(' ')]
    list22 = [int(x) for x in input().split(' ')]
    list1 = sorted(list11)
    list2 = sorted(list22)
    s = 0
    for i in range(n):
        if list11[i] <= list22[i]:
            s +=1
        if s > 1:
            break
    if s > 1:
        def swap(n, list1, list2):
            for i in range(n):
                if list1[i] > list2[i]:
                    return False
    
            return True
        if swap(n, list1, list2):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())

    list1 = sorted([int(x) for x in input().split(' ')])
    list2 = sorted([int(x) for x in input().split(' ')])
    def swap(n, list1, list2):
        for i in range(n):
            if list1[i] > list2[i]:
                return False

        return True
    if swap(n, list1, list2):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())

    list1 = sorted([int(x) for x in input().split(' ')])
    list2 = sorted([int(x) for x in input().split(' ')])
    def swap(n, list1, list2):
        for i in range(n):
            if list1[i] > list2[i]:
                return False

        return True
    if swap(n, list1, list2):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
ax = list(map(int,input().split()))
bx = list(map(int,input().split()))

ax = (sorted(ax))
bx = (sorted(bx))
rx = [a <= b for a,b in zip(ax,bx)]
#print(rx)

if all(rx):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
        ans %= mod
    print(ans)
    return
class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
#C
def C():
    n = II()
    a = LI()
    b = LI()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * (n + 1)
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))
    da = [None] * n
    for i in range(n):
        da[i] = [a[i], i]

    da.sort()
    for i in range(n):
        if da[i][1] == 0:
            check = [1] * n
            c = 1
            while check[i]:
                check[i] = 0
                c += 1
                i = da[i][1]
            if c != n:
                print("Yes")
                return
            break

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                print("Yes")
                return
    print("No")
    return



def Dijkstra(num, start, vedge):

    dist = [float("inf") for i in range(num)]
    dist[0] = 0
    for i in range(num):
        du = dist[i]
        l = i
        for k, j in vedge[i]:
            if dist[j] <= du + k:
                continue
            for j in range(j, i - 1, -1):
                if dist[j] > du + k:
                    dist[j] = du + k
                    continue
                break
    return dist


#D
def D():
    n, m = LI()
    dist = [[] for i in range(n)]
    for _ in range(m):
        l, r, c = LI_()
        c += 1
        dist[l].append([c, r])
    for i in range(n):
        dist[i].sort()
    dist = Dijkstra(n, 0, dist)
    print(dist[n - 1] if dist[n - 1] != inf else -1)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
        ans %= mod
    print(ans)
    return
class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
#C
def C():
    n = II()
    a = LI()
    b = LI()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * (n + 1)
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))
    da = [None] * n
    for i in range(n):
        da[i] = [a[i], i]

    da.sort()
    for i in range(n):
        if da[i][1] == 0:
            check = [1] * n
            c = 0
            while check[i]:
                check[i] = 0
                c += 1
                i = da[i][1]
            if c != n:
                print("Yes")
                return
            break

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                print("Yes")
                return
    print("No")
    return



def Dijkstra(num, start, vedge):

    dist = [float("inf") for i in range(num)]
    dist[0] = 0
    for i in range(num):
        du = dist[i]
        l = i
        for k, j in vedge[i]:
            if dist[j] <= du + k:
                continue
            for j in range(j, i - 1, -1):
                if dist[j] > du + k:
                    dist[j] = du + k
                    continue
                break
    return dist


#D
def D():
    n, m = LI()
    dist = [[] for i in range(n)]
    for _ in range(m):
        l, r, c = LI_()
        c += 1
        dist[l].append([c, r])
    for i in range(n):
        dist[i].sort()
    dist = Dijkstra(n, 0, dist)
    print(dist[n - 1] if dist[n - 1] != inf else -1)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
        ans %= mod
    print(ans)
    return
class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
#C
def C():
    n = II()
    a = LI()
    b = LI()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * (n + 1)
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))
    da = [None] * n
    for i in range(n):
        da[i] = [a[i], i]

    da.sort()
    for i in range(n):
        if da[i][1] == 0:
            check = [1] * n
            c = 0
            while check[i]:
                check[i] = 0
                c += 1
                i = da[da[i][1]][1]
            if c != n:
                print("Yes")
                return

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                print("Yes")
                return
    print("No")
    return



def Dijkstra(num, start, vedge):

    dist = [float("inf") for i in range(num)]
    dist[0] = 0
    for i in range(num):
        du = dist[i]
        l = i
        for k, j in vedge[i]:
            if dist[j] <= du + k:
                continue
            for j in range(j, i - 1, -1):
                if dist[j] > du + k:
                    dist[j] = du + k
                    continue
                break
    return dist


#D
def D():
    n, m = LI()
    dist = [[] for i in range(n)]
    for _ in range(m):
        l, r, c = LI_()
        c += 1
        dist[l].append([c, r])
    for i in range(n):
        dist[i].sort()
    dist = Dijkstra(n, 0, dist)
    print(dist[n - 1] if dist[n - 1] != inf else -1)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()