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:
# -*- coding: utf-8 -*-
a = int(input())
b = input().split()
c = input().split()

for i in range(a):
    b[i] = int(b[i])
    c[i] = int(c[i])

out = "Yes"

def check_max(l, num):
    max_num = 0
    max_i = -1

    l_sorted = sorted(l)
    num_list = [-1] * num
    num_list2 = [-1] * num

    for i in reversed(range(num)):
        for j in range(num):
            if l_sorted[i] == l[j]:
                if num_list[j] == -1:
                    num_list[j] = i+1
                    num_list2[i] = j
                    break

    return (num_list, list(reversed(num_list2)))

def checklist(l1, l2, num):
    result = True
    for i in range(num):
        if l1[i] > l2[i]:
            result = False
            break
    return result 


if out == "Yes":
    swap_num = 0

    num_list_b, num_list_b_index = check_max(b,a)
    num_list_c, num_list_c_index = check_max(c,a)



    for i in range(a-2):
        index1 = num_list_b_index[i]
        index2 = num_list_c_index[i]


        

        if b[index1] <= c[index2]:
            b[index1], b[index2] = b[index2], b[index1]

if not checklist(b, c, a):
    out = "No"
else:
    out = "Yes"

print(out)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = d[0]
max_d = d[-1]
mod = 998244353

if d[0] == d[1] or d[0] != 0:
    print(0)
    exit()
count = [0 for _ in range(max_d+1)]
for i in range(n):
    count[d[i]] += 1
ans = 1
for i in range(max_d):
    n = count[i]
    m = count[i+1]
    ans *= n**m%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

if any(a > b for a, b in zip(sort_A, sort_B)):
    print("No")
    exit()

if all(a > b for a, b in zip(sort_A[1:], sort_B)):
    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()]
flag = False
ans = 'No'
for i in range(n):
    if a[i] == b[i]: #aとbの要素が同じで、1つでも同じ位置に同じ要素があるとき
        flag = True
a.sort()
b.sort()
for i in range(n-1):
    if b[i] < a[i]:
        ans = 'No'
        break
    if b[i] >= a[i+1]:
        ans = 'Yes'
else:
    if flag:
        ans = 'Yes'
if b[-1] < a[-1]:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

for i in range(N):
    if A[i] > B[i]:
        print("No")
        sys.exit(0)

for i in range(1,N):
    if A[i] < B[i-1]:
        print("Yes")
        sys.exit(0)

# ans = "Yes"
# for i in range(N):
#     if A[i] <= B[i]:
#         pass
#     else:
#         ans = "No"
#         break

if True:
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

if any(a > b for a, b in zip(sort_A, sort_B)):
    print("No")
    exit()

if any(a < b for a, b in zip(sort_A[1:], sort_B)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
b = input().split()
c = input().split()

for i in range(a):
    b[i] = int(b[i])
    c[i] = int(c[i])

out = "Yes"

b_sort = sorted(b)
c_sort = sorted(c)

print(b, c)
print(b_sort, c_sort)

for i in range(a):
    if b_sort[i] > c_sort[i]:
        print(i, b_sort[i], c_sort[i])
        out = "No"
        break


max_b = 0
max_bi = -1
fin_list = []

def check_max(l, num):
    max_num = 0
    max_i = -1

    l_sorted = sorted(l)
    num_list = [-1] * num
    num_list2 = [-1] * num

    for i in reversed(range(num)):
        for j in range(num):
            if l_sorted[i] == l[j]:
                if num_list[j] == -1:
                    num_list[j] = i+1
                    num_list2[i] = j
                    break

    return (num_list, list(reversed(num_list2)))

def checklist(l1, l2, num):
    result = True
    for i in range(num):
        if l1[i] > l2[i]:
            result = False
            break
    return result 


if out == "Yes":
    swap_num = 0

    num_list_b, num_list_b_index = check_max(b,a)
    num_list_c, num_list_c_index = check_max(c,a)



    for i in range(a-2):
        index1 = num_list_b_index[i]
        index2 = num_list_c_index[i]


        

        if b[index1] <= c[index2]:
            b[index1], b[index2] = b[index2], b[index1]

if not checklist(b, c, a):
    out = "No"
else:
    out = "Yes"

print(out)

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

from bisect import bisect_left

#インデックス付きソート
#(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()

A3 = index_sort(A)

now = 0
for i in range(N):
    if A3[now][0]==0 and i!=N-1:
        print('Yes')
        exit()
    now = A3[now][0]

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

print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left

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

a = sorted(A)
b = sorted(B)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
        
        
for i in range(N):
    if A[i] <= B[i]:
        l = bisect_left(b,B[i])
        r = bisect_left(b,B[i]+1) - 1
        if r == -1:
            r = 0
        if a[l] <= A[i] <= a[r]:
            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()))
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()))
C=[]
f=0
for i in range(N):
    if A[i]>B[i]:
        f=1
if f==0:
    print("Yes")
    exit()

for i in range(N):
    C.append([A[i],B[i]])
A.sort()
B.sort()
ma=0
for i in range(N):
    if A[i]>B[i]:
        print("No")
        exit()
    elif A[i]==B[i]:
        ma+=1
        
        
C.sort()
cnt=0
for i in range(1,N):
    if C[i-1][1]>C[i][1]:
        cnt+=1
if cnt==1 and ma==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()))

AB = sorted(zip(A,B))
AB.sort(key = lambda x:x[1])

A2,B2 = zip(*AB)
A2 = list(A2)
B2 = list(B2)

cnt = 0
if A2[N-1]>B2[N-1]:
    print('No')
else:
    for i in range(N-2,-1,-1):
        if A2[i]>B2[i]:
            for j in range(i+1,N):
                if A2[i]<=B2[j] and A2[j]<=B2[i]:
                    A2[i],A2[j] = A2[j],A2[i]
                    cnt += 1
                    if cnt > N-2:
                        print('No')
                    break
            else:
                print('No')
                break
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

ans = "Yes"
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        ans = "No"
        break

if ans == "Yes":
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        pass
    else:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = [int(s) for s in input().split()]
b = [int(t) for t in input().split()]
cir = False
ans = 'Yes'

sorta = np.sort(a)
sortb = np.sort(b)
indexa = np.argsort(a)
indexb = np.argsort(b)
index2b = np.concatenate([indexb,indexb])

#循環してるか
for i in range(n):
    if np.all(indexa == index2b[i:i+n]):
        cir = True
        break

if not cir:
    if np.all(sorta <= sortb):
        ans = 'Yes'
    else:
        ans = 'No'

# if ans=='Yes' and cir:
#     ans = 'No'
#     for i in range(1,n-1):
# #         temp = np.array(sorta.copy())
# #         temp[i], temp[i+1] = temp[i+1], temp[i]
#         if sorta[i+1]<= sortb[i]:
#             ans = 'Yes'
#             break
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ab = sorted([[a[i], b[i]] for i in range(n)],key=lambda x:(x[1],x[0]))

    m=131071+n
    segtree=[10**9+1]*(m+1)

    for i in range(131071,m):
        segtree[i] = ab[i - 131071][0]
    for i in range(131070,-1,-1):
        j=2*i+1
        if j>=m:
            segtree[i]=10**9+1
        elif j+1>=m:
            segtree[i]=segtree[j]
        else:
            segtree[i] = min(segtree[j], segtree[j + 1])
    #探す
    def search(i, s):
        if i >= 131071:
            return i - 131071
        if 2*i+3<=m:
            if segtree[2 * i + 2] <= s:
                return search(2 * i + 2, s)
        if 2*i+2<=m:
            if segtree[2 * i + 1] <= s:
                return search(2 * i + 1, s)
        return -1
    
    #更新
    def update_good(i, s):
        if segtree[i] > s:
            segtree[i] = s
            update_good((i - 1) // 2, s)
    
    def update_bad(i, s):
        if i % 2 == 1:
            if segtree[i + 1] > s:
                segtree[(i - 1) // 2] = min(segtree[i+1],segtree[i])
                update_bad((i - 1) // 2, s)
        else:
            if i!=0:
                segtree[(i - 1) // 2] = min(segtree[i-1],segtree[i])
                update_bad((i - 1) // 2, s)

    cnt = 0
    for i in range(n):
        if ab[i][0] > ab[i][1]:
            s = search(0, ab[i][1])
            if s <= i:
                print("No")
                return 0
            update_good(131071 + i, ab[s][0])
            segtree[131071 + s] = ab[i][0]
            update_bad(131071 + s, ab[i][0])
            ab[i][0], ab[s][0] = ab[s][0], ab[i][0]
            cnt+=1
    if cnt <= n - 2:
        print("Yes")
    else:
        print("No")
    
main()

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()
B = LI()

A_c = copy.deepcopy(A)

A.sort()
B.sort()

ans = "Yes"
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        ans = "No"
        break

if ans == "Yes":
    si2i = sorted(range(len(A_c)), key=lambda x:A_c[x])
    a = 0
    count = 0
    while True:
        a = si2i[a]
        if a == 0:
            break
        count += 1

    if count <= N - 2:
        print("Yes")
    else:
        print("No")
else:
    print(ans)

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()))
check=0
for i in range(n):
    if b[i]-a[i]>=0:
        check=1
        break
if check==0:
    print("No")
    sys.exit()
a.sort()
b.sort()
check=0
for _ in range(n):
    if b[_]<a[_]:
        check=1
        break
print("No" if check==1 else "Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ab=[[a[i],b[i]] for i in range(n)]
#print(ab)
a.sort()
b.sort()


for i in range(n):
    if b[i]<a[i]:
        s="No"
        break
else:
    s="Yes"
    #こっちのNoのパターンを省く
    #最大でもN-1回
    ab.sort(key=lambda x:x[1])
    a2=[ab[i][0] for i in range(n)]

    for i in range(n-1):
        a2[i],a2[i+1]=a2[i+1],a2[i]
        if a2[i]!=a[i]:
            break
    else:
        s="No"
print(s)

    #print(a)
    #print(a2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = [int(s) for s in input().split()]
b = [int(t) for t in input().split()]
cir = False
ans = 'Yes'

sorta = np.sort(a)
sortb = np.sort(b)
indexa = np.argsort(a)
indexb = np.argsort(b)
index2b = np.concatenate([indexb,indexb])

#循環してるか
for i in range(n):
    if np.all(indexa == index2b[i:i+n]):
        cir = True
        break

if not cir:
    for i in range(n):
        if sorta[i] > sortb[i]:
            ans = 'No'
        break

# if ans=='Yes' and cir:
#     ans = 'No'
#     for i in range(1,n-1):
# #         temp = np.array(sorta.copy())
# #         temp[i], temp[i+1] = temp[i+1], temp[i]
#         if sorta[i+1]<= sortb[i]:
#             ans = 'Yes'
#             break
print(ans)

Submission status: Wrong Answer

Solution code:
class UnionFind:
    def __init__(self, n):
        self.rank = [0]*n
        self.parent = [i for i in range(n)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
        else:
            self.parent[x] = y
            self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)





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

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

a_.sort()
b_.sort()

ufa = UnionFind(n)
ufb = UnionFind(n)

for i in range(n-1):
    if a_[i][0] == a_[i+1][0]:
        ufa.merge(a_[i][1], a_[i+1][1])
    if b_[i][0] == b_[i+1][0]:
        ufb.merge(b_[i][1], b_[i+1][1])


for i in range(n):
    if ufa.same(a_[i][1], b_[i][1]) or ufb.same(a_[i][1], b_[i][1]):
        print('Yes')
        exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

from bisect import bisect_left

#インデックス付きソート
#(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()

A3 = index_sort(A)
used = [False]*N
used[A3[0][0]] = True
for i in range(N):
    if used[A3[i][0]]:
        print('Yes')
        exit()
    used[A3[i][0]] = True

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

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()
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
    for i in range(n):
        f = True
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i])
            for i in range(first + 1, end):
                if ca[i] <= cb[i - 1]:
                    continue
                f = False
            if f:
                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:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

count1 = 0
count2 = 0

AB = []
AB_new = []
A_new = sorted(A)
B_new = sorted(B)

for i in range(N):
    AB.append([A[i],B[i]])
    AB_new.append([A_new[i],B_new[i]])
    
aaa = sorted(AB, key=lambda x:(x[0],x[1]))

for i in range(N):
    if B_new[i] >= A_new[i]:
        count2 += 1
#print(AB_new)
#print(aaa)

for i in range(N):
    for j in range(i,N):
        if AB_new[i] == aaa[j]:
            count1 = 1
            break
        if AB_new[i][0] < aaa[j][0]:
            break
    if count1 == 1:
        break

if count1 == 1 and count2 == N:
    print("Yes")
else:
    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()]
A_s, B_s = sorted(A), sorted(B)
if any(a > b for a, b in zip(A_s, B_s)):
    print("No")
    quit()
A_idx = [(a, i) for i, a in enumerate(A)]
A_idx.sort()
B = [B[idx] for _, idx in A_idx]
B_idx = [(b, i) for i, b in enumerate(B)]
B_idx.sort()
perm = [i for _, i in B_idx]
cycle_len = 0
used = [False] * N
for i in range(N):
    if used[i]:
        continue
    cnt = 0
    now = i
    while not used[now]:
        used[now] = True
        cnt += 1
        now = perm[now]
    cycle_len += cnt - 1
if cycle_len == N - 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()))

count = 0
y = 0

A_B = []

for n in range(N):
    A_B.append([A[n],B[n]])

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

for n in range(N-1):
    if A_B[n][0] > A_B[n][1]:
        y += 1
        break
    elif A_B[n+1][0] <= A_B[n][1]:
        count += 1

if y >= 1:
    print('No')
elif count >= 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = [int(s) for s in input().split()]
b = [int(t) for t in input().split()]
cir = False
ans = 'Yes'

sorta = np.sort(a)
sortb = np.sort(b)
indexa = np.argsort(a)
indexb = np.argsort(b)
index2b = np.concatenate([indexb,indexb])

#循環してるか
for i in range(n):
    if np.all(indexa == index2b[i:i+n]):
        cir = True
        break

if not cir:
    for i in range(n):
        if sorta[i] > sortb[i]:
            ans = 'No'
        break

if ans=='Yes' and cir:
    ans = 'No'
    for i in range(1,n-1):
#         temp = np.array(sorta.copy())
#         temp[i], temp[i+1] = temp[i+1], temp[i]
        if sorta[i+1]<= sortb[i]:
            ans = 'Yes'
            break
print(ans)

Submission status: Wrong Answer

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

count1 = 0
count2 = 0

AB = []
AB_new = []
A_new = sorted(A)
B_new = sorted(B)

for i in range(N):
    AB.append([A[i],B[i]])
    AB_new.append([A_new[i],B_new[i]])
    
aaa = sorted(AB, key=lambda x:(x[0],x[1]))

for i in range(N):
    if B_new[i] >= A_new[i]:
        count2 += 1
b = 0

for i in range(N):
    for j in range(i,N):
        if AB_new[i] == aaa[j]:
            count1 = 1
            break
        if AB_new[i][1] < aaa[j][1]:
            break
    if count1 == 1:
        break

if count1 == 1 and count2 == N:
    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()
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
    for i in range(n):
        f = True
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i])
            for i in range(first + 1, end):
                if ca[i] <= cb[i]:
                    continue
                f = False
            if f:
                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()