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:
import sys

N=int(input())

a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[[a[i],i] for i in range(N)]
bb=[[b[i],i] for i in range(N)]
aa.sort()
bb.sort()


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

for i in range(N-1):
    if aa[i][0]==aa[i+1][0] or bb[i][0]==bb[i+1][0]:
        print("Yes")
        sys.exit()

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


dic={}
for i in range(N):
    dic[aa[i][0]]=i

inij=1
tmp=1
j=inij

while tmp<N:
    j=dic[a[j]]
    if j==inij: print("Yes"),sys.exit()
    tmp+=1

print("No")

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import bisect as bi
import numpy as np
import sys
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
b.sort()
ab = np.dstack([a,b])
ab = [flatten for inner in ab for flatten in inner]
ab.sort(key=itemgetter(1))

tmplist = []
#tmp = 0
cnt = 0

for i in range(n):
    if ab[i][0] > ab[i][1]:
        index = bi.bisect_left(b,ab[i][0])
        if index == n:
            print('No')
            sys.exit()
        #tmp = ab[index][0]
        for j in range(index,n):
            tmp = ab[j][0]
            if tmp >= ab[i][1]:
                ab[j][0], ab[i][0] = ab[i][0], ab[j][0]
                break
            elif j == n-1:
                print('No')
                sys.exit()
            #ab[index][0] , ab[i][0] = ab[i][0] , ab[index][0]
        cnt += 1
        if cnt > 2*n:
            print('No')
            sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def main():
    in_number = int(input())
    NumberSequenceA = input()
    NumberSequenceB = input()
    wk_A = sorted(NumberSequenceA)
    wk_B = sorted(NumberSequenceB)
    print(wk_A)
    print(wk_B)
    for i in range(in_number):
      if wk_A[i] > wk_B[i]:
        pass
      else:
        print('No')
        return 0
    print(Yes)
    return 0

main()

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    ac = sorted(a)
    bc = sorted(b)
    d = collections.defaultdict(dict)
    for i in range(n):
        d[ac[i]][bc[i]] = 0
        if ac[i] > bc[i]:
            print("No")
            exit()
    dif = collections.defaultdict(list)
    for i in range(n):
        if b[i] not in d[a[i]]:
            dif[a[i]] += [b[i]]
    print("Yes" if len(dif) <= n - 1 or len(dif) == 0 else "No")


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

count = 0
count2 = 0
count3 = 0

for i in range(len(A)):
    if A[i] > B[i]:
        count += 1
        count2 += 1
    elif A[i] < B[i]:
        count += -1
    else:
        pass

A.sort(reverse=True)
B.sort(reverse=True)
# print(A)
for i in range(len(A)):
    if A[i] > B[i]:
        count3 += 1
    else:
        pass

if count == 0 and count2 <= N-2 and count3 <= 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

flag=0
count = 0
Aa = 0
Bb = 0
diff = [0 for i in range(N)]

for i in range(N):
  if(A[i] > B[i]):
    count+=1
  diff[i] = B[i] - A[i]
  
  if(B[i] > Bb):
    Bb = B[i]
  if(A[i] > Aa):
    Aa = A[i]

if(count >= N or Aa > Bb):
  #No
  flag = 1    

#sorting
for i in range(N):
  pass



#  print(i)
  #if(N-i == 0):
  

if(N%2 == 0):
  count -= 1


#output
#print(N)
#print(A)
#print(B)

if(flag == 0):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

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

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

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

from bisect import bisect_left

#インデックス付きソート
#(index,value)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

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

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

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

A3 = index_sort(A)
B3 = index_sort(B)

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    p1 = bisect_left(A2,A[bindex])
    p2 = bisect_left(A2,A[aindex])
    A3[p1][0] = p2
    A3[p2][0] = p1


for i in range(N):
    if A[i]>B[i]:
        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
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]:
                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()))
cnt=0
i=B.index(max(B)); j=A.index(max(A))
while cnt <= N-2:
	if B[i] < A[j]:
		print('No')
		exit()
	else:
		B.pop(i); A.pop(j)
		cnt+=1
		i=B.index(max(B)); j=A.index(max(A))
for i in range(len(B)):
	if B[i] < A[i]:
		print('No')
		exit()
print('Yes')

Submission status: Wrong Answer

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

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

table = collections.defaultdict(set)
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[AA[i]] = i
    IB[BB[i]] = i

for i in range(N):
    if AA[i] > BB[i]:
        print("No")
        break
else:
    i = 0
    j = 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:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
err=0
for i in range(n):
    if a[i]>b[i]:
        err+=1
a1=sorted(a)
b1=sorted(b)
# print(a1)
# print(b1)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        quit()
# print(err)
if err<n-1:
    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()
ans = "Yes"
for i in range(n):
    if a[i]>b[i]: ans="No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

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

mod = 10**9 + 7

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

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

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

from bisect import bisect_left

#インデックス付きソート
#(index,value)の順に格納
def index_sort(A):
    a = []
    for i,x in enumerate(A):
        a.append([i,x])
    return sorted(a,key=lambda x: x[1])

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

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

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

A3 = index_sort(A)
B3 = index_sort(B)

for i in range(2,N)[::-1]:
    bindex = B3[i][0]
    aindex = A3[i][0]
    if aindex==bindex:
        print('Yes')
        exit()
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    p1 = bisect_left(A2,A[bindex])
    A3[i][0] = p1


for i in range(N):
    if A[i]>B[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()))
a1 = sorted(a)
b1 = sorted(b)
smaller = True
for i in range(n):
    if a1[i]>b1[i]:
        smaller = False
        break
if smaller:
  if n == 3:
    k=0
    for i in range(n):
      if a[i]>b[i]:
        k+=1
    if k==2:
      print('No')
    else:
      print('Yes')
  else:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

table = collections.defaultdict(set)

if max(A) > max(B) or min(B) < min(A):
    print("No")
    exit(0)

for i in range(N):
    table[A[i]].add(B[i])

B.sort()
A.sort()

count = 0
for i in range(N):
    if A[i] <= B[i]:
        if B[i] in table[A[i]]:
            count += 1
    else:
        print("No")
        exit(0)
if count > 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

    aa = [[a[i], i] for i in range(n)]
    bb = [[b[i], i] for i in range(n)]

    aa.sort()
    bb.sort()

    mn = 0
    idx = 0
    for i in range(n):
        ai = aa[i][1]
        bi = bb[i][1]
        if ai - bi < mn:
            mn = ai - bi
            idx = ai

    a.pop(idx)
    b.pop(idx)
    a.sort()
    b.sort()

    bl = True
    for ae, be in zip(a, b):
        if ae > be:
            bl = False
            break

    print("Yes" if bl else "No")


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

num = 0
for i in range(n):
    if a[i] > b[i]:
        num += 1
if num >= n-2:
    print('No')
    exit()

a.sort()
b.sort()

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

print('Yes')

Submission status: Wrong Answer

Solution code:


def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    A.sort()
    B.sort()
    for i in range(N):
        if A[i] > B[i]:
            print("No")
            break
    else:
        print("Yes")


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
err=0
for i in range(n):
    if a[i]>b[i]:
        err+=1
a1=sorted(a)
b1=sorted(b)
# print(a1)
# print(b1)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        quit()
# print(err)
if err<n-1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import bisect as bi
import numpy as np
import sys
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
b.sort()
ab = np.dstack([a,b])
ab = [flatten for inner in ab for flatten in inner]
ab.sort(key=itemgetter(1))

tmplist = []
#tmp = 0
cnt = 0

for i in range(n):
    if ab[i][0] > ab[i][1]:
        index = bi.bisect_left(b,ab[i][0])
        if index == n:
            print('No')
            sys.exit()
        #tmp = ab[index][0]
        for j in range(index,n):
            tmp = ab[j][0]
            if tmp >= ab[i][1]:
                ab[j][0], ab[i][0] = ab[i][0], ab[j][0]
                break
            elif j == n-1:
                print('No')
                sys.exit()
            #ab[index][0] , ab[i][0] = ab[i][0] , ab[index][0]
        cnt += 1
        if cnt > n + 2:
            print('No')
            sys.exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sort_A = sorted(A)
    sort_B = sorted(B)
    for i in range(N):
        if sort_A[i] > sort_B[i]:
            print('No')
            exit()
    B_cnt = [0] * N
    for i, b in enumerate(sort_B):
        B_cnt[i] = bisect.bisect_right(sort_A, b)

    for i in range(N):
        if i + 1 > B_cnt[i]:
            print('No')
            exit()
    cnt = 0
    for i in range(N):
        if A[i] <= B[i]:
            cnt += 1

    if cnt < 2:
        print('No')
        exit()

    print('Yes')

    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

flag=0
count = 0
Aa = 0
Bb = 0
diff = [0 for i in range(N)]

for i in range(N):
  if(A[i] > B[i]):
    count+=1
  diff[i] = B[i] - A[i]
  
  if(B[i] > Bb):
    Bb = B[i]
  if(A[i] > Aa):
    Aa = A[i]

if(count >= N or Aa > Bb):
  #No
  flag = 1    

#sorting
for i in range(N):
  pass



#  print(i)
  #if(N-i == 0):
  

if(N%2 == 0):
  count -= 1

#output
print(N)
#print(A)
#print(B)

if(flag == 0):
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
err=0
for i in range(n):
    if a[i]>b[i]:
        err+=1
a1=sorted(a)
b1=sorted(b)
print(a1)
print(b1)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        quit()
print(err)
if err<n-1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
las=sorted(la)
lbs=sorted(lb)
for i in range(n):
    if las[i]>lbs[i]:
        print("No")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n:
    print("Yes")
    exit()
lc=sorted([[lb[i],la[i]] for i in range(n)])
a=[0]*n
for num,i in enumerate(lc):
    a[num]=bisect.bisect_left(las,i[1])
used = [ False ] * n
cnt = 0
for i in range(n):
    j = i
    used[j] = True
    while a[j] != j:
        j = a[j]
        if used[j]:
            break
        used[j] = True
        cnt += 1
if cnt<n-1:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt

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

sorted_A = sorted(A)
sorted_B = sorted(B)

for i in range(N):
    if sorted_A[i] > sorted_B[i]:
        print("No")
        exit(0)
        
if (bubble_sort(A) - bubble_sort(B)) <= 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_sort = sorted(A)
B_sort = sorted(B)
rep = {}
for i, (a, b) in enumerate(zip(A_sort, B_sort)):
    if a > b:
        print("No")
        exit()
    if a < b:
        if a not in rep:
            rep[a] = {b}
        else:
            rep[a] += {b}
    
for a, b in zip(A, B):
    if a == b:
        print("Yes")
        exit()
    if a in rep:
        if b in rep[a]:
            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()))

num = 0
for i in range(n):
    if a[i] > b[i]:
        num += 1
if num >= n:
    print('No')
    exit()

a.sort()
b.sort()

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

print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls, b_ls = zip(*sorted([(a, b) for a, b in zip(a_ls, b_ls)], key=lambda x:x[1]))
a_ls = list(a_ls)
cnt = 0
last = n - 1
sorted_a_ls = sorted(a_ls)
ct_non_swap = sum([1 if i >= j else 0 for i, j in zip(sorted_a_ls, a_ls)])
is_possible = all([True if a <= b else False for a, b in zip(sorted_a_ls, b_ls)])
if is_possible and ct_non_swap >= 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
las=sorted(la)
lbs=sorted(lb)
for i in range(n):
    if las[i]>lbs[i]:
        print("No")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n:
    print("Yes")
    exit()
lc=sorted([[lb[i],la[i]] for i in range(n)])
a=[0]*n
for num,i in enumerate(lc):
    a[num]=bisect.bisect_left(las,i[1])
used = [ False ] * n
cnt = 0
for i in range(n):
    j = i
    used[j] = True
    while a[j] != j:
        j = a[j]
        if used[j]:
            break
        used[j] = True
        cnt += 1
print(cnt)
if cnt<n-1:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    ac = sorted(a)
    bc = sorted(b)
    d = collections.defaultdict(dict)
    for i in range(n):
        d[ac[i]][bc[i]] = 0
        if ac[i] > bc[i]:
            print("No")
            exit()
    dif = collections.defaultdict(list)
    for i in range(n):
        if b[i] not in d[a[i]]:
            dif[a[i]] += [b[i]]
    print("Yes" if len(dif) <= n - 1 else "No")


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def selectionsort(a,n):
  counter = 0
  for i in range(n-1):
    idx = None
    mi = a[i]
    flag = False
    for x in reversed(range(i,n)):
      if mi > a[x]:
        idx = x
        mi = a[x]
        counter+=1
        flag = True
    if flag:
      a[i],a[idx] = a[idx],a[i]
    if counter > n - 2:
      return a, 10000000000000
  return a, counter
 
len = int(input())
a = sorted([int(i) for i in input().split(" ")])
b = [int(i) for i in input().split(" ")]
b, counter = selectionsort(b,len)

Flag = True

if counter == 10000000000000:
  print("No")
  

else:
  for i in range(len):
    if a[i] > b[i]:
      print("No")
      Flag = False
      break
      

  if Flag:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

sortA = sorted(A)
sortB = sorted(B)

D = np.array(sortA) <= np.array(sortB)
if D.sum() != n:
    print('No')
    exit()

C = np.array(sortA[1:]) <= np.array(sortB[:-1])
count = C.sum()
if count == 0:
    if sortA[:-1] == A[1:]:
        print('No')
        exit()
    else:
        print('Yes')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
AB = [[A[i],B[i]] for i in range(N)]
AB.sort(key=lambda x:x[1])

A = [[A[i],i] for i in range(N)]
A.sort(key=lambda x:x[0])
da = {}
for i in range(N):
    j = A[i][1]
    da[j] = i 
B.sort()
c0 = [0]*(N+1)
c1 = [0]*N
c2 = [0]*N
A = [A[i][0] for i in range(N)]
for i in range(N-1):
    if A[i]<=B[i+1]:
        c1[i] = 1
    if A[i+1]<=B[i]:
        c2[i] = 1
for i in range(N):
    if A[i]<=B[i]:
        c0[i] = 1
for i in range(N-2):
    c1[i+1] += c1[i]
    c2[i+1] += c2[i]
for i in range(N-1):
    c0[i+1] += c0[i]
A = [AB[i][0] for i in range(N)]
ans = False
for n in range(N):
    m = da[n]
    if n < m:
        if c0[n-1]==n and c0[N-1]-c0[m]==N-m-1 and c1[m-1]-c1[n-1]==m-n and A[n]<=B[n]:
            ans = True
    else:
        if c0[m-1]==m and c0[N-1]-c0[n]==N-n-1 and c2[n-1]-c2[m-1]==n-m and A[n]<=B[n]:
            ans = True
if ans:
    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()))

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

a.sort()
b.sort()

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

print('Yes')

Submission status: Wrong Answer

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

As = sorted(A)
Bs = sorted(B)


for i in range(N):
    if As[i]>Bs[i]:
        print("No")
        break
else:
    ALR = []
    l = 0
    r = 0
    for i in range(N):
        while r+1<=N-1 and As[r+1]<=Bs[i]:
            r += 1
        while l+1<=N-1 and As[l]>Bs[i]:
            l += 1
        ALR.append([As[i],Bs[l],Bs[r]])
    AB = [[a,b] for a,b in zip(A,B)]
    AB.sort(key = lambda x:x[0])
    cnt = 0
    for i in range(N):
        if AB[i][0] > AB[i][1]:
            cnt += 1
        elif ALR[i][2]<AB[i][1]:
            cnt += 1
    if cnt <= N-2:
        print("Yes")
    else:
        print("No")

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(N):
    if A[i] in tmp[B[i]]:
      print("Yes")
      return 0
  print("No")
      
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xs = [int(i) for i in input().split()]
ys = [int(i) for i in input().split()]

valid = True
s = True

if(xs[0]>ys[0]):
    s = False
c = 0
for i in range(1,n):
    if(s):
        if(xs[i]>ys[i]):
            s=False
            c += 1
    else:
        if(xs[i]<=ys[i]):
            s=True
            c += 1

if(c==1):
    valid = False
    print("No")

xs.sort()
ys.sort()

for i in range(n):
    if (xs[i]>ys[i]):
        valid = False
        print("No")
        break

if(valid):
    print("Yes")

Submission status: Wrong Answer

Solution code:


# unionfind木構造
# unionfindについてはここhttps://www.slideshare.net/chokudai/union-find-49066733
# グループに属するかの判定(find)や、グループ結合(union)に強い

from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
As  = list(map(int, input().split()))
Bs  = list(map(int, input().split()))
As_ind = [(a,i) for i,a in enumerate(As)]
Bs_ind = [(b,i) for i,b in enumerate(Bs)]
As_ind.sort()
Bs_ind.sort()


uf = UnionFind(N)
d_list = defaultdict(list)
for A,B in zip(As_ind,Bs_ind):
    # print(A,B)
    if A[0] > B[0]:
        print("No")
        exit()
    uf.union(A[1],B[1])
    d_list[uf.find(A[1])].append(A[0])


d_ans = defaultdict(int)
for i in range(N):
    root = uf.find(i)
    d_ans[root] += 1
if len(d_ans) >= 2:
    print("Yes")
else:
    # コーナーケース(dの値？))
    for k in d_list.keys():
        if len(d_list[k]) > len(set(d_list[k])):
            print("Yes")
            exit()
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def init(n):
  for i in range(N+1):
    par[i] = i
    rnk[i] = 0
def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
def unite(x, y):
  x = find(x)
  y = find(y)
  if x == y:
    return
  if (rnk[x] < rnk[y]):
    par[x] = y
  else:
    par[y] = x
    if(rnk[x] == rnk[y]):
      rnk[x] += 1
def same(x, y):
  return find(x) == find(y)

N = I()
a = IL()
b = IL()

par = [0 for i in range(N+1)]
rnk = [0 for i in range(N+1)]
init(N)

adata = []
bdata = []
for i in range(N):
  adata.append([a[i], i])
  bdata.append([b[i], i])
adata.sort()
bdata.sort()
#print(adata)
#print(bdata)

for i in range(N):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  if atmp > btmp:
    print("No")
    exit()

for i in range(N-1):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  #print("---")
  #print(atmp,aID)
  #print(btmp,bID)
  if aID == bID:
      break
  if same(aID, bID):
    break
  else:
    unite(aID, bID)
else:
  print("No")
  exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

AI = [(a, i) for i, a in enumerate(A)]
BI = [(b, i) for i, b in enumerate(B)]
AI.sort()
BI.sort()

orderA = {}
orderB = {}

for k, ((_, i), (_, j)) in enumerate(zip(AI, BI)):
    orderA[i] = k
    orderB[j] = k

A = orderA.values()
B = orderB.values()

aToI = {a : i for i, a in enumerate(A)}

cnt = 0
visited = [True] * N
for i, a in enumerate(A):
    if visited[i]:
        continue
    visited[i] = True
    now = aToI[B[i]]
    leng = 0
    while now != a:
        now = aToI[B[i]]
        leng += 1
    cnt += leng

if cnt <= N - 2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
xs = [int(i) for i in input().split()]
ys = [int(i) for i in input().split()]

valid = True
s = True

if(xs[0]>ys[0]):
    s = False
c = 0
for i in range(1,n):
    if(s):
        if(xs[i]>ys[i]):
            s=False
            c += 1
    else:
        if(xs[i]<=ys[i]):
            s=True
            c += 1

print(c)
if(c==1):
    valid = False
    print("No")

xs.sort()
ys.sort()

for i in range(n):
    if (xs[i]>ys[i]):
        valid = False
        print("No")
        break

if(valid):
    print("Yes")

Submission status: Wrong Answer

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

count1 = 0
count2 = 0

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

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

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

if count1 == 1 and count2 == N:
    print("Yes")
else:
    print("No")