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,=map(int,input().split())
*B,=map(int,input().split())

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

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

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy as copy
from operator import itemgetter
input = sys.stdin.readline

def compress(lis, n=2, last_sort=False):
    length = len(lis)
    first_value = -1
    for i in range(n):
        lis.sort(key=itemgetter(i))
        value = first_value
        index = 0
        for j in range(length):
            if lis[j][i] != value:
                index += 1
            value = lis[j][i]
            lis[j][i] = index
    
    if last_sort: lis.sort()
    return lis
                

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]
    

def main():
    n = int(input())
    sub1 = list(map(int, input().split()))
    sub2 = list(map(int, input().split()))
    
    key = [[x, i] for i, x in enumerate(sub1+sub2)]
    compress(key)

    a = [x[0] for x in key[:n]]
    b = [x[0] for x in key[n:]]
    
    a_sort = [(a[i], i) for i in range(n)]
    b_sort = [(b[i], i) for i in range(n)]
    a_sort.sort()
    b_sort.sort()
    
    judge = True
    
    for i in range(n):
        if a_sort[i][0] > b_sort[i][0]:
            judge = False
            break

    judge2 = False
    
    if judge:
        for i in range(n):
            if a_sort[i][1] == b_sort[i][1]:
                judge2 = True
                break
        if not judge2:
            union = UnionFind(n*2)
            for i in range(n):
                if union.same(a[a_sort[i][1]], a[b_sort[i][1]]):
                    continue
                union.union(a[a_sort[i][1]], a[b_sort[i][1]])
            key = -min(union.par)
            if key != n:
                judge2 = True
                
                
    if judge and judge2:
        print("Yes")
    else:
        print("No")
    
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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])
a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]
sa = sorted(a)
if not all(sa[i]<=b[i] for i in range(n)):
    ans = "No"
else:
    if any(a[i]<=b[i] for i in range(n)):
        ans = "Yes"
    else:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

balist=[]
for i in range(N):
  a=alist[i]
  b=blist[i]
  balist.append((b,a))
balist.sort()
  
a2list=[]
for b,a in balist:
  a2list.append(a)
#print(a2list)

fix_index=-1
for i in range(N):
  if a2list[i]<=balist[i][0]:
    fix_index=i
    break    
#print(fix_index)

if fix_index==-1:
  print("No")
  sys.exit(0)

a2_fix=-1
a2mlist=[]
for i in range(N):
  if i==fix_index:
    a2_fix=a2list[i]
  else:
    a2mlist.append(a2list[i])    
#print(a2_fix,a2mlist)
a2mlist.sort(reverse=True)

a3list=[]
for i in range(N):
  if i==fix_index:
    a3list.append(a2_fix)
  else:
    a3list.append(a2mlist.pop())    
#print(a3list)

for i in range(N):
  if a3list[i]>balist[i][0]:
    print("No")
    break
else:
  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()
for i in range(N):
  if alist[i]>blist[i]:
    print("No")
    break
else:
  print("Yes")

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()))
C = sorted(zip(B, A))
B, A = zip(*C)
D = sorted((a, i) for i, a in enumerate(A))
for i, (d, idx) in enumerate(D):
  if idx <= i and d <= B[idx]:
    s, t = i, idx
    break
else:
  print("No")
  exit()
A, indices = zip(*D)
A = list(A)
A[s], A[t] = A[t], A[s]
for a, b in zip(A, B):
  if a > b:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [ [int(s),i]  for i,s in enumerate(input().split())]
b = [ [int(s),i]  for i,s in enumerate(input().split())]
a.sort(reverse=True)
b.sort(reverse=True)

go = [-1] * n

b_ind = 0
ans = 'No'
for a_ind, (j,j_ind) in enumerate(a):
    while(b[b_ind][0] >= j ):
        b_ind += 1

        if(b_ind == n)&(a_ind < n-1):
            print('Yes')
            exit()

        if(b_ind == n):
            break

    if(b_ind == a_ind):
        print('No')
        exit()

    if(b_ind > a_ind+1):
        ans = 'Yes'

now = 0
cnt = 0
for _ in range(n-1):
    now = go[now]
    cnt += 1
    if(now==0):
        print('Yes')
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
n = int(input())
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
ab=np.array([np.array([a[i],b[i]]) for i in range(n)])
ab=ab[np.argsort(ab[:,1])]
a.sort()
b.sort()
for i in range(n):
    if a[i]>b[i]:
        print("No")
        exit()
for i in range(n-1):
    if ab[0,0]>ab[0,1]:
        s = np.searchsorted(b,ab[0,0])
        if s<len(ab):
            ab[0,0]=ab[s,0]
            ab=np.delete(ab,s,0)
            b=np.delete(a,s)
        else:
            print("No")
            exit()
    else:
        print("Yes")
        exit()
#print(ans)
print("No")

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
import sys
input = sys.stdin.readline
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)]
ab.sort(key=lambda x:x[1])
a.sort()
b.sort()
# print(a,b)
# print(ab)
for i in range(n):
    if a[i]>b[i]:
        print("No")
        exit()
for i in range(n-1):
    if ab[0][0]>ab[0][1]:
        s = bisect_left(b,ab[0][0])
        if s<len(ab):
            ab[0][0]=ab[s][0]
            ab.pop(s)
            b.pop(s)
        else:
            print("No")
            exit()
    else:
        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()))

s_b = sorted(b)
s_a = sorted(a)


for i in range(n):
    if s_a > s_b:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか2,3,4,5,1もダメ
    
    A1=sorted(A)
    B1=sorted(B)
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    cnt=0#A[i]>=B[i]なる個数
    
    for i in range(N):
        if A[i]>=B[i]:
            cnt+=1
            
    flag2=1#B[-1]+B[0:N-1]が単調非減少か
    B=list(B)
    now=-1
    for j in range(-1,N-1):
        i=j%N
        if B[i]<now:
            flag2=0
            break
        now=B[i]
        
        
    flag3=1#B[1:]+B[0]が単調非減少か
    now=-1
    for j in range(1,N+1):
        i=j%N
        if B[i]<now:
            flag3=0
            break
        now=B[i]
        
    #print(cnt,flag,flag2,flag3)    
    
    if cnt==1 and (A[-1]>=B[-1]) and(B[-1]<A[1]) and flag2:
        flag=0
        
                
    if cnt==(N-1) and flag3:
        flag=0
    
    
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか
    
    A1=sorted(A)
    B1=sorted(B)
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    cnt=0#A[i]<B[i]なる個数
    
    for i in range(N):
        if A[i]>=B[i]:
            cnt+=1
            
    flag2=1#B[-1]+B[1:N-1]が単調非減少か
    B=list(B)
    now=-1
    for j in range(-1,N-1):
        i=j%N
        if B[i]<now:
            flag2=0
            break
        now=B[i]
        
        
    flag3=1#B[1:]+B[0]が単調非減少か
    now=-1
    for j in range(1,N+1):
        i=j%N
        if B[i]<now:
            flag3=0
            break
        now=B[i]
        
    if cnt==1 and (A[-1]>=B[-1]) and flag2:
        flag=0
        
                
    if cnt==(N-1) and flag3:
        flag=0
    
    
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか
    
    A1=sorted(A)
    B1=sorted(B)
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    cnt=0#A[i]<B[i]なる個数
    
    for i in range(N):
        if A[i]>=B[i]:
            cnt+=1
            
    flag2=1#B[0]+B[1:]が単調非減少か
    B=list(B)
    now=-1
    for j in range(N-1,2*N-1):
        i=j%N
        if B[i]<now:
            flag2=0
            break
        now=B[i]
        
        
    flag3=1#B[1:]+B[0]が単調非減少か
    B.append(B[0])
    now=-1
    for i in range(1,N+1):
        if B[i]<now:
            flag3=0
            break
        now=B[i]
        
    if cnt==1 and flag2:
        flag=0
                
    if cnt==(N-1) and flag3:
        flag=0
    
    
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか
    
    A1=sorted(A)
    B1=sorted(B)
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    cnt=0#A[i]<B[i]なる個数
    
    for i in range(N):
        if A[i]>=B[i]:
            cnt+=1
        
        
    flag3=1#B[1:]+B[0]が単調非減少か
    B=list(B)
    B.append(B[0])
    now=-1
    for i in range(1,N+1):
        if B[i]<now:
            flag3=0
            break
        now=B[i]
                
    if cnt==(N-1) and flag3:
        flag=0
    
    
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    #=>A:1,2,3,4,5
    #  B:5,1,2,3,4みたいなケースが無理になるのか
    
    A1=sorted(A)
    B1=sorted(B)
    
    flag=1
    
    #回数制限なしでできるか
    for i in range(N):
        if B1[i]<A1[i]:
            flag=0
            break
        
    flag2=1#元々全てのiに対してA[i]<B[i]か
    
    for i in range(N):
        if A[i]>=B[i]:
            flag2=0
            break
        
        
    flag3=1#Bが単調非減少か
    if flag2:
        now=-1
        for i in range(N):
            if B[i]<now:
                flag3=0
                break
            now=B[i]
                
    if flag2 and flag3:
        flag=0
    
        
        
    if flag==1:
        print("Yes")
    else:
        print("No")
    
  
    

main()

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    #A,B=zip(*sorted(zip(A,B)))
    
    
    #基本的にBを恥からソートしてもN-1回，完全逆順とかならそれはそれで楽にソートできるので，
    #結局はBをソートするだけの話? 流石に違う気もするが...
    
    flag=1
    A.sort()
    B.sort()
    
    for i in range(N):
        if B[i]<A[i]:
            flag=0
            break
        
    if flag==1:
        print("Yes")
    else:
        print("No")
            
    
    

main()

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
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)]

check=True
Ainc=True
Binc=True
ABinc=True
A.sort()
B.sort()

for i in range(N):
    if A[i][0]>B[i][0]:
        check=False
    if i>0:
        if A[i-1]==A[i]:
            Ainc=False
        if B[i-1]==B[i]:
            Binc=False
        if B[i-1]>=A[i]:
            ABinc=False

if not check:
    print("No")
else:
    if (not Ainc) or (not Binc) or (not ABinc):
        print("Yes")
    else:
        ans=[-1]*N
        for i in range(N):
            ans[B[i][1]]=A[i][1]+1

        n=N
        #A1 ... AnのBIT(1-indexed)
        BIT = [0]*(n+1)

        #A1 ~ Aiまでの和 O(logN)
        def BIT_query(idx):
            res_sum = 0
            while idx > 0:
                res_sum += BIT[idx]
                idx -= idx&(-idx)
            return res_sum

        #Ai += x O(logN)
        def BIT_update(idx,x):
            while idx <= n:
                BIT[idx] += x
                idx += idx&(-idx)
            return

        res=0
        for i in range(N):
            res+=i-BIT_query(ans[i])
            BIT_update(ans[i],1)
        if res%2==N%2:
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A=[(A[i],i) for i in range(N)]
B=[(B[i],i) for i in range(N)]

check=True
Ainc=True
Binc=True
ABinc=True
A.sort()
B.sort()

for i in range(N):
    if A[i][0]>B[i][0]:
        check=False
    if i>0:
        if A[i-1]==A[i]:
            Ainc=False
        if B[i-1]==B[i]:
            Binc=False
        if B[i-1]>=A[i]:
            ABinc=False

if not check:
    print("No")
else:
    if not Ainc or not Binc or not ABinc:
        print("Yes")
    else:
        ans=[-1]*N
        for i in range(N):
            ans[B[i][1]]=A[i][1]+1

        n=N
        #A1 ... AnのBIT(1-indexed)
        BIT = [0]*(n+1)

        #A1 ~ Aiまでの和 O(logN)
        def BIT_query(idx):
            res_sum = 0
            while idx > 0:
                res_sum += BIT[idx]
                idx -= idx&(-idx)
            return res_sum

        #Ai += x O(logN)
        def BIT_update(idx,x):
            while idx <= n:
                BIT[idx] += x
                idx += idx&(-idx)
            return

        res=0
        for i in range(N):
            res+=i-BIT_query(ans[i])
            BIT_update(ans[i],1)
        if res%2==N%2:
            print("Yes")
        else:
            print("No")

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()))
bi = [[b[i],i] for i in range(n)]
bi.sort()
flg = 0
if len(set(b)) == n:
  for i in range(n):
    bi[i][0] = i
  bi.sort(key = lambda x:x[1])
  idc = list(zip(*bi))[0]
  cnt = 0
  plc = 0
  while True:
    plc = idc[plc]
    cnt += 1
    if plc == 0:
      break
  if cnt == n:
    flg = 1
a.sort()
b.sort()
for x,y in zip(a,b):
  if x > y:
    print("No")
    exit()
if not flg:
  print("Yes")
else:
  for i in range(1,n):
    if a[i] <= b[i-1]:
      print("Yes")
      exit()
  print("No")

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()))
bi = [(b[i],i) for i in range(n)]
bi.sort()
idc = list(zip(*bi))[1]
flg = 0
cnt = 0
plc = 0
while True:
  plc = idc[plc]
  cnt += 1
  if plc == 0:
    break
if cnt == n and len(set(b)) == n:
  flg = 1
a.sort()
b.sort()
for x,y in zip(a,b):
  if x > y:
    print("No")
    exit()
if not flg:
  print("Yes")
else:
  print(2/0)
  for i in range(1,n):
    if a[i] <= b[i-1]:
      print("Yes")
      exit()
  print("No")

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()))
bi = [(b[i],i) for i in range(n)]
bi.sort()
idc = list(zip(*bi))[1]
flg = 0
cnt = 0
plc = 0
while True:
  plc = idc[plc]
  cnt += 1
  if plc == 0:
    break
if cnt == n and len(set(b)) == n:
  flg = 1
a.sort()
b.sort()
for x,y in zip(a,b):
  if x > y:
    print("No")
    exit()
if not flg:
  print("Yes")
else:
  print("No")
  exit()
  for i in range(1,n):
    if a[i] <= b[i-1]:
      print("Yes")
      exit()
  print("No")

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()))
bi = [(b[i],i) for i in range(n)]
bi.sort()
idc = list(zip(*bi))[1]
flg = 0
cnt = 0
plc = 0
while True:
  plc = idc[plc]
  cnt += 1
  if plc == 0:
    break
if cnt == n and len(set(b)) == n:
  flg = 1
a.sort()
b.sort()
for x,y in zip(a,b):
  if x > y:
    print("No")
    exit()
if not flg:
  print("Yes")
else:
  for i in range(1,n):
    if a[i] <= b[i-1]:
      print(2/0)
      print("Yes")
      exit()
  print("No")

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()))
bi = [(b[i],i) for i in range(n)]
bi.sort()
idc = list(zip(*bi))[1]
flg = 0
cnt = 0
plc = 0
while True:
  plc = idc[plc]
  cnt += 1
  if plc == 0:
    break
if cnt == n and len(set(b)) == n:
  flg = 1
a.sort()
b.sort()
for x,y in zip(a,b):
  if x > y:
    print("No")
    exit()
if not flg:
  print("Yes")
else:
  for i in range(1,n):
    if a[i] <= b[i-1]:
      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()))
b.sort()
a=[(a[i],i)for i in range(n)]
a.sort()
c=[j for i,j in a]
a=[i for i,j in a]
m=c[c[0]]
d=1
while m!=c[0]:m=c[m];d+=1
for i in range(n):
  if a[i]>b[i]:print("No");exit()
if d!=n:print("Yes");exit()
for i in range(1,n):
  if b[i-1]>=a[i]:print("Yes");exit()
print("No");exit()

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()))
sortedA = sorted(A)
sortedB = sorted(B)
for i in range(n):
  if sortedA[i] > sortedB[i]:
    print("No")
    exit()
AB = sorted([(A[i], B[i]) for i in range(n)])
C = sorted([(ab[1], i) for i, ab in enumerate(AB)])
idx = [c[1] for c in C]
for i, j in enumerate(idx):
  if idx[j] == i:
    print("Yes")
    break
else:
  print("No")

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline

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

    for a, b in zip(sorted(A), sorted(B)):
        if a > b:
            print('No')
            exit()
    if len(set(A)) != N or len(set(B)) != N:
        print('Yes')
        exit()

    AB = [(a, b) for a, b in zip(A, B)]
    AB.sort(key=lambda x: x[1])
    A_new = [ab[0] for ab in AB]
    a2i = {a: i for i, a in enumerate(A_new)}
    A_cmp = [0] * N
    for i, a in enumerate(sorted(A_new)):
        A_cmp[a2i[a]] = i
    cnt = 0
    i = 0
    seen = [0] * N
    while True:
        if not seen[i]:
            seen[i] = 1
            cnt += 1
            i = A_cmp[i]
        else:
            break
    if cnt == N:
        print('No')
    else:
        print('Yes')


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

changeable_pairs = {}
change_required_pairs = {}

for i in range(n):
    if a[i] == b[i]:
        continue
    elif a[i] > b[i]:
        change_required_pairs[i] = { 'a': a[i], 'b': b[i] }
    else:
        changeable_pairs[i] = { 'a': a[i], 'b': b[i] }

# print(changeable_pairs)
# print(change_required_pairs)

def select_best_pair(a, b):
    global changeable_pairs
    i = None
    for k, v in changeable_pairs.items():
        target_a = v['a']
        target_b = v['b']
        if target_a <= b and a <= target_b:
            if i is None:
                i = k
            else:
                current_a = changeable_pairs[i]['a']
                current_b = changeable_pairs[i]['b']
                if target_a > current_a or target_b < current_b:
                    i = k
    # if i is not None:
    #     changeable_pairs.pop(i)
    return i


count = 0
for k, v in change_required_pairs.items():
    i = select_best_pair(v['a'], v['b'])
    # print(i)
    if i is not None:
        count += 1
# print(count)
if len(change_required_pairs) <= count and count <= n - 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
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()))
c = sorted([[a[i], b[i]] for i in range(n)], key=lambda x: x[1])
a = [(x[0], i) for i, x in enumerate(c)]
b = [x[1] for x in c]
a.sort()
for i in range(n):
	if a[i][0] > b[i]:
		print("No")
		sys.exit()
cur, cnt = 0, 0
while a[cur][1] != 0:
	cnt += 1
	cur = a[cur][1]
if cnt < n-1:
	print("Yes")
else:
	for i in range(n-1):
		if a[i][0] <= b[i+1]:
			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()))
c = sorted([[a[i], b[i]] for i in range(n)], key=lambda x: x[1])
a = [(x[0], i) for i, x in enumerate(c)]
b = [x[1] for x in c]
a.sort()
print(a)
for i in range(n):
	if a[i][0] > b[i]:
		print("No")
		sys.exit()
cur, cnt = 0, 0
while a[cur][1] != 0:
	cnt += 1
	cur = a[cur][1]
if cnt < n-1:
	print("Yes")
else:
	for i in range(n-1):
		if a[i][0] <= b[i+1]:
			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()))

C = sorted(A)
D = sorted(B)

for i in range(N):
    if C[i] > D[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()))

a.sort()
b.sort()

i = 0
while i < N:
  if (b[i] - a[i] < 0):
    print('No')
    break
  i += 1
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()
c = []
for i in range(N):
  check = b[i] - a[i]
  if check < 0:
    print('No')
    break
  else:
    c.append(check)
    
print('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():
    class UnionFind():
        def __init__(self, n):
            self.parent = [-1 for _ in range(n)]
            # 正==子: 根の頂点番号 / 負==根: 連結頂点数

        def find(self, x):
            # 要素xが属するグループの根を返す
            if self.parent[x] < 0:
                return x
            else:
                self.parent[x] = self.find(self.parent[x])
                return self.parent[x]

        def unite(self, x, y):
            # 要素xが属するグループと要素yが属するグループとを併合する
            x, y = self.find(x), self.find(y)
            if x == y:
                return False
            else:
                if self.size(x) < self.size(y):
                    x, y = y, x
                self.parent[x] += self.parent[y]
                self.parent[y] = x

        def same(self, x, y):
            # 要素x, yが同じグループに属するかどうかを返す
            return self.find(x) == self.find(y)

        def size(self, x):
            # 要素xが属するグループのサイズ（要素数）を返す
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            # すべての根の要素をリストで返す
            return self.parent[x] < 0

        def members(self, x):
            # 要素xが属するグループに属する要素をリストで返す
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def group_count(self):
            # グループの数を返す
            return len(self.roots())

        def all_group_members(self):
            # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
            return {r: self.members(r) for r in self.roots()}
    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
    uf = UnionFind(N)
    indices_A = [i for i in range(len(A))]
    sorted_indices_A = sorted(indices_A, key=lambda i: A[i])
    for i in range(N):
        uf.unite(i,sorted_indices_A[i])
    if uf.size(0)<N:
        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()

"""

"""