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:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
    if D[0]!=0 or d[0]!=1:
        print(0)
        return
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    indices = [i for i in range(len(B))]
    sorted_indices = sorted(indices, key=lambda i: B[i])
    sorted_B = [B[i] for i in sorted_indices]
    sorted_A = sorted(A)
#    print(sorted_B); print(sorted_indices)
    d = defaultdict(int)
#    print(sortA,sortB)
    for i in range(N):
        d[sorted_A[i]] = sorted_B[i]
        if sorted_A[i]>sorted_B[i]:
            print("No")
            return
    for i in range(N-1):
        if sorted_A[i+1]<=sorted_B[i]:
            print("Yes")
            return
    for i in range(N):
        a = sorted_indices[i]
        if d[A[a]]==B[i]:
            print("Yes")
            return
    print("No")
    return

def examD():
    class Dijkstra(object):
        """
        construct: O(ElogV)
        """

        def __init__(self, edges, start=0):
            """
            :param list of list of list of int edges:
            :param int start=0:
            """
            self.__dist = [inf] * len(edges)
            self.__dist[start] = 0
            self.__calculate(edges, start)

        @property
        def dist(self):
            return self.__dist

        def __calculate(self, edges, start):
            Q = [(0, start)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                for u, cost in edges[v]:
                    if self.dist[u] > self.dist[v] + cost:
                        self.__dist[u] = self.dist[v] + cost
                        heapq.heappush(Q, (self.dist[u], u))
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        l, r, c = LI()
        l -=1; r -=1
        V[l].append((r,c))
    for i in range(N-1):
        V[i+1].append((i,0))
#    print(V)
    D = Dijkstra(V)
    ans = D.dist[N-1]
    if ans==inf:
        ans = -1
    print(ans)
    return

def examE():
    N, K = LI()
    ans = [[]for _ in range(N)]


    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
    if D[0]!=0 or d[0]!=1:
        print(0)
        return
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    sortA = sorted(A)
    sortB = sorted(B)
    d = defaultdict(int)
#    print(sortA,sortB)
    for i in range(N):
        d[sortA[i]] = sortB[i]
        if sortA[i]>sortB[i]:
            print("No")
            return
    for i in range(N-1):
        if sortA[i+1]<=sortB[i]:
            print("Yes")
            return
    for i in range(N):
        if d[A[i]]==B[i]:
            print("Yes")
            return
    print("No")
    return

def examD():
    class Dijkstra(object):
        """
        construct: O(ElogV)
        """

        def __init__(self, edges, start=0):
            """
            :param list of list of list of int edges:
            :param int start=0:
            """
            self.__dist = [inf] * len(edges)
            self.__dist[start] = 0
            self.__calculate(edges, start)

        @property
        def dist(self):
            return self.__dist

        def __calculate(self, edges, start):
            Q = [(0, start)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                for u, cost in edges[v]:
                    if self.dist[u] > self.dist[v] + cost:
                        self.__dist[u] = self.dist[v] + cost
                        heapq.heappush(Q, (self.dist[u], u))
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        l, r, c = LI()
        l -=1; r -=1
        V[l].append((r,c))
    for i in range(N-1):
        V[i+1].append((i,0))
#    print(V)
    D = Dijkstra(V)
    ans = D.dist[N-1]
    if ans==inf:
        ans = -1
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
    if D[0]!=0 or d[0]!=1:
        print(0)
        return
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    sortA = sorted(A)
    sortB = sorted(B)
    d = defaultdict(int)
#    print(sortA,sortB)
    for i in range(N):
        d[sortA[i]] = sortB[i]
        if sortA[i]>sortB[i]:
            print("No")
            return
    for i in range(N-1):
        if sortA[i]<=sortB[i+1]:
            print("Yes")
            return
    for i in range(N):
        if d[A[i]]==B[i]:
            print("Yes")
            return
    print("No")
    return

def examD():
    class Dijkstra(object):
        """
        construct: O(ElogV)
        """

        def __init__(self, edges, start=0):
            """
            :param list of list of list of int edges:
            :param int start=0:
            """
            self.__dist = [inf] * len(edges)
            self.__dist[start] = 0
            self.__calculate(edges, start)

        @property
        def dist(self):
            return self.__dist

        def __calculate(self, edges, start):
            Q = [(0, start)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                for u, cost in edges[v]:
                    if self.dist[u] > self.dist[v] + cost:
                        self.__dist[u] = self.dist[v] + cost
                        heapq.heappush(Q, (self.dist[u], u))
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        l, r, c = LI()
        l -=1; r -=1
        V[l].append((r,c))
    for i in range(N-1):
        V[i+1].append((i,0))
#    print(V)
    D = Dijkstra(V)
    ans = D.dist[N-1]
    if ans==inf:
        ans = -1
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
    if D[0]!=0 or d[0]!=1:
        print(0)
        return
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    N = I()
    A = LI()
    B = LI()
    sortA = sorted(A)
    sortB = sorted(B)
    d = defaultdict(int)
#    print(sortA,sortB)
    for i in range(N):
        d[sortA[i]] = sortB[i]
        if sortA[i]>sortB[i]:
            print("No")
            return
    for i in range(N-1):
        if sortA[i]>=sortB[i+1]:
            print("Yes")
            return
    for i in range(N):
        if d[A[i]]==B[i]:
            print("Yes")
            return
    print("No")
    return

def examD():
    class Dijkstra(object):
        """
        construct: O(ElogV)
        """

        def __init__(self, edges, start=0):
            """
            :param list of list of list of int edges:
            :param int start=0:
            """
            self.__dist = [inf] * len(edges)
            self.__dist[start] = 0
            self.__calculate(edges, start)

        @property
        def dist(self):
            return self.__dist

        def __calculate(self, edges, start):
            Q = [(0, start)]  # (dist,vertex)
            while (Q):
                dist, v = heapq.heappop(Q)
                if self.dist[v] < dist: continue  # 候補として挙がったd,vだが、他に短いのがある
                for u, cost in edges[v]:
                    if self.dist[u] > self.dist[v] + cost:
                        self.__dist[u] = self.dist[v] + cost
                        heapq.heappush(Q, (self.dist[u], u))
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        l, r, c = LI()
        l -=1; r -=1
        V[l].append((r,c))
    for i in range(N-1):
        V[i+1].append((i,0))
#    print(V)
    D = Dijkstra(V)
    ans = D.dist[N-1]
    if ans==inf:
        ans = -1
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Wrong Answer

Solution code:
from bisect import bisect
inf=float("inf")
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
D=[]
for i in range(N):
    C.append([A[i],i])
    D.append([B[i],i])
C.sort()
D.sort()

count=0
data=[0 for i in range(N)]
for i in range(N):
    d=D[i][0]
    b=bisect(C,[d,inf])
    if b<=i:
        print("No")
        break
    elif d>i+1:
        count=1
    data[C[i][1]]=D[i][1]
else:
    if count==1:
        print("No")
    else:
        flag=[0]*N
        num=0
        flag[0]=1
        count=1
        for i in range(N+1):
            num=data[num]
            if flag[num]==0:
                flag[num]=1
                count+=1
                continue
            else:
                break
        if count==N:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
from bisect import bisect
inf=float("inf")
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
D=[]
for i in range(N):
    C.append([A[i],i])
    D.append([B[i],i])
C.sort()
D.sort()

count=0
data=[0 for i in range(N)]
for i in range(N):
    d=D[i][0]
    b=bisect(C,[d,inf])
    if b<=i:
        print("No")
        break
    elif d>i+1:
        count=1
    data[C[i][1]]=D[i][1]
else:
    if count==1:
        print("Yes")
    else:
        flag=[0]*N
        num=0
        flag[0]=1
        count=1
        for i in range(N+1):
            num=data[num]
            if flag[num]==0:
                flag[num]=1
                count+=1
                continue
            else:
                break
        if count==N:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
from bisect import bisect
inf=float("inf")
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
D=[]
for i in range(N):
    C.append([A[i],i])
    D.append([B[i],i])
C.sort()
D.sort()

count=0
data=[0 for i in range(N)]
for i in range(N):
    d=D[i][0]
    b=bisect(C,[d,inf])
    if b<=i:
        print("No")
        break
    elif d>i+1:
        count=1
    data[C[i][1]]=i
else:
    if count==1:
        print("Yes")
    else:
        flag=[0]*N
        num=0
        flag[0]=1
        count=1
        for i in range(N+1):
            num=data[num]
            if flag[num]==0:
                flag[num]=1
                count+=1
                continue
            else:
                break
        if count==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()
if A[-1] <= B[-1]:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

sa = sorted(A)
sb = sorted(B)

flag = True
for i in range(N):
    if sa[i] > sb[i]:
        flag = False
        break

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()
a = [(a[i],i) for i in range(n)]
a.sort()
b.sort()
for i in range(n):
    if b[i] < a[i][0]:
        print('No')
        quit()

edges = [None]*n
for i in range(n):
    edges[a[i][1]] = i
lst = [None]*n
def dfs(s):
    if lst[s] == None:
        lst[s] = tmp
        dfs(edges[s])
    return

tmp = 0
for i in range(n):
    if lst[i] == None:
        dfs(i)
        tmp += 1

lst = list(Counter(lst).values())
if len(lst) >= 2:
    print('Yes')
    quit()

for i in range(n-1):
    if b[i] >= a[i+1][0]:
        print('Yes')
        quit()

print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()
a = [(a[i],i) for i in range(n)]
a.sort()
b.sort()
for i in range(n):
    if b[i] < a[i][0]:
        print('No')
        quit()

edges = [None]*n
for i in range(n):
    edges[a[i][1]] = i
lst = [None]*n
def dfs(s):
    if lst[s] == None:
        lst[s] = tmp
        dfs(edges[s])
    return

tmp = 0
for i in range(n):
    dfs(i)
    tmp += 1

lst = list(Counter(lst).values())
if len(lst) >= 2:
    print('Yes')
    quit()
for i in range(n-1):
    if b[i] >= a[i+1][0]:
        print('Yes')
        quit()

print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def union(x,y):
    x = root(x)
    y = root(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
par = [i for i in range(n)]
rank = [0]*n
a = LI()
b = LI()
a = [(a[i],i) for i in range(n)]
a.sort()
b.sort()
for i in range(n):
    if b[i] < a[i][0]:
        print('No')
        quit()

for i in range(n):
    if root(a[i][1]) != root(i):
        union(a[i][1],i)

cnt = [0]*n
for i in range(n):
    cnt[root(i)] = 1
s = sum(cnt)
if s >= 2:
    print('Yes')
    quit()
for i in range(n-1):
    if b[i] >= a[i+1][0]:
        print('Yes')
        quit()

print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()

a.sort()
b.sort()
for i in range(n):
    if b[i] < a[i]:
        print('No')
        quit()
for i in range(n-1):
    if (b[i] <= a[i+1]):
        print('Yes')
        quit()

print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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()

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

for i in range(n-1):
    if a[i] <= b[i+1]:
        print('Yes')
        quit()
print('No')

Submission status: Wrong Answer

Solution code:
class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]

N, *AB = map(int, open(0).read().split())
A, B = AB[:N], AB[N:]

A.sort()
B.sort()

if any(a > b for a, b in zip(A, B)):
    print("No")
    quit()

AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))

uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
    uf.union(i, j)

parents = {uf.find(i) for i in range(N)}
if len(parents) >= 2:
    print("Yes")
    quit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
liis = []
lii = []
for i in range(n):
  if lis[i] > li[i]:
    liis.append(lis[i])
    lii.append(li[i])
lis.sort()
li.sort()
for i in range(n):
  if lis[i] > li[i]:
    print("No")
    exit()
cnt = max(len(liis)-1,0)
liis.sort(reverse=True)
lii.sort()
for i in range(len(liis)):
  if liis[i] > lii[i]:
    cnt += 1
if cnt > n-2:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
li = list(map(int,input().split()))
lis.sort()
li.sort()
for i in range(n):
  if lis[i] > li[i]:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect as br
from collections import Counter
readline = sys.stdin.readline

def check(A, B):
    SA = sorted(A)
    SB = sorted(B)
    if any(a > b for a, b in zip(SA, SB)):
        return 'No'
    if all(a <= b for a, b in zip(SA, SB)):
        return 'Yes'
    if any(br(SA, B[i]) != i+1 for i in range(N)):
        return 'Yes'
    if len(set(A)) != N or len(set(B)) != N:
        return 'Yes'
    P = [None]*N
    Aidx = Counter()
    Bidx = Counter()
    for i in range(N):
        a = A[i]
        b = B[i]
        Aidx[a] = i
        Bidx[b] = i
        
    for i in range(N):
        sa = SA[i]
        sb = SB[i]
        P[Aidx[sa]] = P[Bidx[sb]]
    
    visited = set()
    vn = 0
    while vn not in visited:
        visited.add(vn)
        vn = P[vn]
    if len(visited) == N:
        return 'No'
    return 'Yes'

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

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

Submission status: Wrong Answer

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

C = sorted(A)
D = sorted(B)
flag = 0
for i in range(N):
    if C[i] > D[i]:
        flag = 1
        break
if flag == 0:
    for i in range(N-1):
        if C[i+1] <= D[i]:
            flag = 2
            break
        
if flag <= 1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

C = sorted(A)
D = sorted(B)
flag = 0
for i in range(N):
    if C[i] > D[i]:
        flag = 1
        break
        
if flag == 1:
    print("No")
else:
    count = 0
    for i in range(N):
        if A[i] > B[i]:
            count+=1
    if count >= 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
if max(A) > max(B) or min(A) > min(B):
    print("No")
    exit()
for i in range(N):
    if A[i] > B[i]:
        count = count + 1
if count > 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(" ")))
count = 0
if max(A) > max(B):
    print("No")
    exit()
for i in range(N):
    if A[i] > B[i]:
        count = count + 1
if count > 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(" ")))
count = 0
for i in range(N):
    if A[i] > B[i]:
        count = count + 1
if count > 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()))
l = list(zip(b, a))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
    
fir, las, val = {}, {}, {}
s = [0] * n
for i in range(n):
  if b[i] not in fir:
    fir[b[i]] = i
  las[a[i]] = i
  if b[i] not in val:
    val[b[i]] = a[i]
  if i > 0 and a[i] <= b[i - 1]:
    s[i] = 1
for i in range(1, n):
  s[i] += s[i - 1]
 
for x, y in l:
  if x >= y:
    if y >= val[x] or s[fir[x]] - s[las[y]] == fir[x] - las[y]:
      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()))
# n = 10000
# a = list(range(n))
# b = list(range(n))
# import random
# random.shuffle(b)
l = sorted(list(zip(b, a)))
 
a.sort()
b.sort()
for i in range(n):
  if a[i] > b[i]:
    print('No')
    exit()
    
fir, las = {}, {}
s = [0] * n
for i in range(n):
  if b[i] not in fir:
    fir[b[i]] = i
  las[a[i]] = i
  if i > 0 and a[i] <= b[i - 1]:
    s[i] = 1
for i in range(1, n):
  s[i] += s[i - 1]
 
for i, (x, y) in enumerate(l):
  if x >= y:
    if y >= a[i] or s[fir[x]] - s[las[y]] == fir[x] - las[y]:
      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()
    
pos = {}
s = [0] * n
for i in range(n):
  pos[a[i]] = i
  if i > 0 and a[i] <= b[i - 1]:
    s[i] = 1
for i in range(1, n):
  s[i] += s[i - 1]

for i, (x, y) in enumerate(l):
  if x >= y:
    if y >= a[i] or s[i] - s[pos[y]] == i - pos[y]:
      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()))

aa = a[:]
bb = b[:]

aa.sort()
bb.sort()

flag = 0
for i in range(n):
    if aa[i] > bb[i]:
        print("No")
        exit(0)
    if i and aa[i] <= bb[i - 1]:
        flag = 1

if flag:
    print("Yes")
    exit(0)



sta = [0] * 100005

from bisect import *

pos = 0
cnt = 1
while cnt <= n - 1:
    sta[pos] = 1
    pos = bisect_left(bb, a[pos])
    cnt += 1
    if sta[pos] and cnt <= n - 1:
        print("Yes")
        exit(0)

print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = np.array(input().split(), dtype=np.int)
b = np.array(input().split(), dtype=np.int)
sort_a = np.sort(a)
sort_b = np.sort(b)
if np.all(sort_a <= sort_b) and np.any(sort_a[1:] <= sort_b[:-1]):
  print('Yes')
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 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()

def count(start,id):
    co = 0
    s = start

    while True:
        s = id[s]
        co += 1
        if s == 0:
            break
    return co

L = []

for i in range(n):
    L.append([A[i],B[i]])
L.sort(key=lambda x:x[1])
p = sorted(range(n) , key = lambda i:L[i][0])
print(p)
A.sort()
print(p)


bo1 = all(A[i] <= L[i][1] for i in range(n))
bo2 = any(A[i+1] <= L[i][1] for i in range(n-1))
bo3 = count(0,p) <= n-2

print("Yes" if (bo1 and (bo2 or bo3)) else "No")