Problem:


Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes



Sample input:
3
1 3 2
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]
AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                print("No")
            else:
                print("No")

Submission status: Wrong Answer

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

a.sort()
b.sort()
han = False
for i in range(n):
    if a[i] <= b[i]:
        continue
    else:
        han = False
        break
    if i < n-1:
        if a[i+1] <= b[i]:
            han = True
if han:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]
AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("No")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]
AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("No")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                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 ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        ppppp = 0
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][0] >= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    break
        else:
            count += 1


if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

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

a.sort()
b.sort()
result = 'Yes'
han = False
for i in range(n):
    if a[i] <= b[i]:
        continue
    else:
        han = False
        result = 'No'
        break
    if i < n-1:
        if a[i+1] <= b[i]:
            han = True
if han:
    print(result)
else:
    print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]
AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline
import copy

#ライブラリインポート
from collections import defaultdict

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

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

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

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	AA = copy.deepcopy(A)
	BB = copy.deepcopy(B)
	AA = sorted(AA)
	BB = sorted(BB)
	judge = "Yes"
	for i in range(N):
		if AA[i] > BB[i]:
			judge = "No"
			break

	if judge == "No":
		print("No")
	else:
		UF = UnionFind(N)
		C = [[B[i], i] for i in range(N)]
		C = sorted(C)
		for i in range(N):
			UF.union(i, C[i][1])
		
		for i in range(N):
			UF.par[i] = UF.find(i)
		if UF.size[UF.find(i)] == N:
			print("No")
		else:
			print("Yes")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        ppppp = 0
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][0] >= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    break
        else:
            count += 1


if count >= n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][0] >= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    ppppp=0
                    break
        else:
            count += 1


if count >= n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[A[i]] == IB[B[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                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()))

AB = [[A[i],B[i]] for i in range(N)]
AB.sort(key=lambda x:x[1])

A.sort()
B.sort()

ans = False
for i in range(N-1):
    if B[i]>=A[i+1]:
        ans = True

for i in range(N):
    if AB[i] == [A[i],B[i]]:
        ans = True

for i in range(N):
    if A[i]>B[i]:
        ans = False
if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline
import copy

#ライブラリインポート
from collections import defaultdict

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

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

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

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	AA = copy.deepcopy(A)
	BB = copy.deepcopy(B)
	AA = sorted(AA)
	BB = sorted(BB)
	judge = "Yes"
	for i in range(N):
		if AA[i] > BB[i]:
			judge = "No"
			break

	if judge == "No":
		print("No")
	else:
		UF = UnionFind(N)
		C = [[B[i], i] for i in range(N)]
		C = sorted(C)
		for i in range(N):
			UF.union(i, C[i][1])
		
		for i in range(N):
			UF.par[i] = UF.find(i)
		if UF.size[0] == N:
			print("No")
		else:
			print("Yes")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

#na = [a[i] for bi,i in pb]
na = []
from itertools import groupby
for k,g in groupby(pb,key=lambda x: x[0]):
    g = list(g)
    res = [a[i] for bi,i in g]
    res.sort()
    #print(g)
    na += res

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    if na == sa[1:] + sa[:1]:
        ok = 0
    
#print(a,b,na)

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

Submission status: Wrong Answer

Solution code:
import bisect

mod = 1000000007

def main():
    n = int(input())
    a = [x for x in map(int,input().split())]
    b = [x for x in map(int,input().split())]
    cnt = 0
    for i in range(n):
        if a[i]>b[i]:
            cnt += 1
    if cnt>n-2:
        print("No")
        return
    a.sort()
    b.sort()
    for i in range(n):
        if a[i]>b[i]:
            print("No")
            return
    for i in range(1,n):
        if a[i]<b[i-1]:
            print("Yes")
            return
    print("Yes")
    return


if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B, A = zip(*sorted(zip(B, A)))
a = sorted(A)

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

for i in range(N - 1):
    if B[i] >= A[i + 1]:
        print('Yes')
        exit()
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

#na = [a[i] for bi,i in pb]
na = []
from itertools import groupby
for k,g in groupby(pb):
    g = list(g)
    res = [a[i] for bi,i in g]
    res.sort()
    na += res

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    if na == sa[1:] + sa[:1]:
        ok = 0
    
#print(a,b,na)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[A[i]] = i
    IB[B[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    for i in range(1, N):
        if AA[i] <= BB[i-1]:
            print("Yes")
            break
    else:
        for i in range(N):
            if IA[AA[i]] == IB[BB[i]]:
                print("Yes")
                break
        else:
            c = 1
            i = IA[A[0]]
            i = IA[A[IB[B[i]]]]
            while i != IA[A[0]]:
                i = IA[A[IB[B[i]]]]
                c += 1
            if c < N:
                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 = sorted(A)
B.sort()

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

for i in range(N - 1):
    if B[i] >= A[i + 1]:
        print('Yes')
        exit()
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
BA = [(b, a) for (b, a) in zip(B, A)]
BA.sort()
B, A = list(map(list, zip(*BA)))  # BA.T
AI = [(a, i) for (i, a) in enumerate(A)]
AI.sort()
C, P = list(map(list, zip(*AI)))  # AI.T

def can_divide_cycle(P):
    start = P[0]
    ncycle = 1
    cur = start
    while P[cur] != start:
        cur = P[cur]
        ncycle += 1
    return ncycle < len(P)

vld = all(c <= b for (c, b) in zip(C, B)) \
    and (can_divide_cycle(P) or any(c >= b for (c, b) in zip(C[1:], B[:-1])))
print('Yes' if vld else 'No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]

AA = sorted(A)
BB = sorted(B)

IA = {}
IB = {}
for i in range(N):
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    i = 0
    k = 0
    X = [0] * N
    Y = [0] * N
    for j in range(N):
        while i < N - 1 and AA[i+1] <= BB[j]:
            i += 1
        X[j] = i
        Y[j] = k
        if i == j: k = i + 1
    
    for i in range(N):
        if Y[IB[B[i]]] <= IA[A[i]] <= X[IB[B[i]]]:
            print("Yes")
            break
    else:
        c = 1
        i = IA[A[0]]
        i = IA[A[IB[B[i]]]]
        while i != IA[A[0]]:
            i = IA[A[IB[B[i]]]]
            c += 1
        if c < N:
            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 = sorted(A)
b = sorted(B)

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

for i in range(N - 1):
    if B[i] >= A[i + 1]:
        print('Yes')
        exit()
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

na = [a[i] for bi,i in pb]

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    if na == sa[1:] + sa[:1]:
        ok = 0
    
#print(a,b,na)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
N = int(input())

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

a = sorted(A, reverse=True)
b = sorted(B, reverse=True)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
        
s = 0
count = 0

if a[0] > b[1]:
    while A[0] < a[0]:
        s = a.index(A[0])
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")
    else:
        print("Yes")

else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = [1 for i in range(n)]
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][0] >= bb[i][0] and ppppp[j+kkk[k][0]]:
                ppppp[i] = 0
                break
        else:
            count += 1



if count >= n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

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

from bisect import bisect_left
from operator import itemgetter


def main():
    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')
            return

    for ind, a in enumerate(C):
        i = bisect_left(D, a)
        if ind != i:
            print('Yes')
            return
    E = [(C[0], D[N-1])]
    for i in range(N-1):
        E.append((C[i+1], D[i]))
    
    E.sort(key=itemgetter(1))
    E.sort(key=itemgetter(0))

    F = []
    for i in range(N):
        F.append((A[i], B[i]))
    F.sort(key=itemgetter(1))
    F.sort(key=itemgetter(0))
    
    for i in range(N):
        if F[i] != E[i]:
            print('Yes')
            return 
    
    print('No')
    return 

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

na = [a[i] for bi,i in pb]

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(a[1:],b):
    if i <= j: break
else:
    if na == a[1:] + a[0]:
        ok = 0
    

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
A = [(A[i]<<18) + i for i in range(N)]
B = [(B[i]<<18) + i + (1<<17) for i in range(N)]

AA = sorted(A)
BB = sorted(B)

IA1 = {}
IB1 = {}

IA = {}
IB = {}
for i in range(N):
    IA1[A[i]] = i
    IB1[B[i]] = i
    IA[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    i = 0
    k = 0
    X = [0] * N
    Y = [0] * N
    for j in range(N):
        while i < N - 1 and AA[i+1] <= BB[j]:
            i += 1
        X[j] = i
        Y[j] = k
        if i == j: k = i + 1
    
    for i in range(N):
        if Y[IB[B[i]]] <= IA[A[i]] <= X[IB[B[i]]]:
            print("Yes")
            break
    else:
        c = 1
        i = IA[A[0]]
        i = IA[A[IB[B[i]]]]
        while i != IA[A[0]]:
            i = IA[A[IB[B[i]]]]
            c += 1
        if c < N-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()))

a.sort()
b.sort()
result = 'Yes'
han = 0
for i in range(n):
    if a[i] <= b[i]:
        continue
    else:
        han = 0
        result = 'No'
        break
    if i < n-1:
        if a[i+1] <= b[i]:
            han = 1
if han:
    print(result)
else:
    print(result)

Submission status: Wrong Answer

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

a.sort()
b.sort()

s = "Yes"

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

print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split()])
B = np.array([int(x) for x in input().split()])
I = B.argsort()
A = A[I]
B = B[I]
calc = max(A) <= max(B)
if not calc:
    print("No")
    exit(0)
if any(np.sort(A)[1:] <= B[:-1]):
    print('Yes')
    exit()
p = A.argsort().tolist()
x = 0
c = 0
while True:
    c += 1
    x = p[x]
    if x == 0:
        break
print("Yes" if p != N else "No")

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split()])
B = np.array([int(x) for x in input().split()])
I = B.argsort()
A = A[I]
B = B[I]
calc = max(A) <= max(B)
if not calc:
    print("No")
    exit(0)
p = A.argsort().tolist()
x = 0
c = 0
while True:
    c += 1
    x = p[x]
    if x == 0:
        break
print("Yes" if p != N else "No")

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

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