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=list(map(int,input().split()))
A=a.copy()
b=list(map(int,input().split()))
B=b.copy()
a=sorted(a)
b=sorted(b)

C=[0 for i in range(n)]
for j in range(n):
    C[j]=(A[j],B[j])
C=sorted(C,key=lambda x:(x[1],x[0]))
D=[0 for i in range(n)]
for i in range(n):
    D[i]=C[i][0]
flag=True
flag2=True
for j in range(n):
    if a[j]>b[j]:
        flag=False
        break
counter=0
for k in range(n):
    if D[k]!=a[k]:
        counter+=1
if counter==n:
    flag2=False
if flag and flag2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt


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

a.sort()
b.sort()


for i in range(n):
    if b[i]<a[i]:
        s="No"
        break
else:
    s="Yes"

ab.sort(key=lambda x:x[1])
for i in range(n-1):
    a[-1-i],a[-2-i]=a[-2-i],a[-1-i]


a2=[]
for i in range(n):
    a2.append(ab[0])

if a2==a:
    s="No"

print(s)

Submission status: Wrong Answer

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

    a.sort(); b.sort()

    o = "Yes"
    for i in range(n):
        if a[i]>b[i]:
            o = "No"; break

    print(o)

if __name__ == "__main__":
    f_c()

Submission status: Wrong Answer

Solution code:
N=int(input())
A1=[int(s) for s in input().split()]
B1=[int(s) for s in input().split()]
A2=[(A1[i],i) for i in range(N)]
B2=[(B1[i],i) for i in range(N)]
A=sorted(A2)
B=sorted(B2)
#print(A)
#print(B)
for i in range(N):
  if B[i][0]<A[i][0]:
    print("No")
    break
else:
  for i in range(N-1):
    if B[i][0]>=A[i+1][0]:
      print("Yes")
      break
  else:
    k=0
    for i in range(N-1):
      k=B[k][1]
      if k==0:
        print("Yes")
        break
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
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=list(map(int,input().split()))
b=list(map(int,input().split()))
s=sorted([[a[i],i]for i in range(n)])
t=sorted([[b[i],i]for i in range(n)])
p,q,r=0,0,0
for i in range(n):
    if p>=s[i][0]:
        r+=1
    if s[i][0]<=t[i][0]:
        if s[i][1]!=t[i][1]:
            q+=1
        p=t[i][0]
    else:
        print("No")
        break
else:
    if q!=n or r>0:
        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)
lab=sorted(lb)
for i in range(n):
    if las[i]>lab[i]:
        print("No")
        exit()
sa=set(la)
sb=set(lb)
if len(sa)!=n or len(sb)!=n:
    print("Yes")
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:
import sys
import math as mp
from itertools import permutations

def l_i():
    arr = [int(a) for a in input().strip().split(' ')]
    return arr
c=0
n=int(input())
ar=sorted(l_i())
br=sorted(l_i())
for i in range(n):
    if(ar[i]<=br[i]):
        c=c+1
    else:
        print('NO')
        break
if(c==n):
    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'
for i in range(n):
    if a[i] <= b[i]:
        continue
    else:
        result = 'No'
        break
print(result)

Submission status: Wrong Answer

Solution code:
N=int(input())
A1=[int(s) for s in input().split()]
B1=[int(s) for s in input().split()]
A2=[(A1[i],i) for i in range(N)]
B2=[(B1[i],i) for i in range(N)]
A=sorted(A2)
B=sorted(B2)
print(A)
print(B)
for i in range(N):
  if B[i][0]<A[i][0]:
    print("No")
    break
else:
  for i in range(N-1):
    if B[i][0]>=A[i+1][0]:
      print("Yes")
      break
  else:
    k=0
    for i in range(N-1):
      k=B[k][1]
      if k==0:
        print("Yes")
        break
    else:
      print("No")

Submission status: Wrong Answer

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

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

a.sort()
b.sort()

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
        ans %= mod
    print(ans)
    return
class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self.bit = [0 for _ in range(size)]
        self.size = size

    def add(self, i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += self.bit[x - 1]
            x -= x & -x
        return res

    def search(self, x):
        """
        二分探索。和がx以上となる最小のインデックス(>= 1)を返す
        :param int x:
        :return :
        """
        i = 1
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.bit[i + step - 1] < x:
                i += step
                s += self.bit[i - 1]
            step >>= 1
        return i

    def __len__(self):
        return self.size
#C
def C():
    n = II()
    a = LI()
    b = LI()
    tmp = [inf, inf]
    res = None
    for i in range(n):
        if tmp[0] >= b[i] - a[i] >= 0 and b[i] < tmp[1]:
            res = i
            tmp = [b[i] - a[i], b[i]]
    if res == None:
        print("No")
        return
    del a[res]
    del b[res]
    a.sort()
    b.sort()
    ans = 0
    bit = BinaryIndexedTree(b[-1] + 1)
    n -= 1
    for i in range(n):
        tmp = bisect_right(a, b[i]) - bit.sum(b[i])
        bit.add(b[i],1)
        if tmp <= 0:
            print("No")
            return
    print("Yes")

    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[]
f=0
for i in range(N):
    if A[i]>B[i]:
        f=1
if f==0:
    print("Yes")
    exit()

for i in range(N):
    C.append([A[i],B[i]])
A.sort()
B.sort()
for i in range(N):
    if A[i]>B[i]:
        print("No")
        exit()
        
C.sort()
cnt=0
for i in range(1,N):
    if C[i-1][1]>C[i][1]:
        cnt+=1
if cnt==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [[b[i],a[i]] for i in range(n)]
c.sort()
a = [c[i][1] for i in range(n) ]
b = [c[i][0] for i in range(n) ]
#print(a)
#print(b)
cnt = n - 2
for i in range(n):
    if a[i] > b[i]:
        if cnt < 0:
            print("No")
            exit()
        #tmpa = a[i:]
        disa = [a[i+j]-b[i] for j in range(n-i)]
        #print(a[i],disa)
        k = disa.index(min(disa))+i
        a[i],a[k] = a[k],a[i]
        cnt -= 1
        if a[i] > b[i]:
            print("No")
            exit()
#print(a)
#print(b)
print("Yes")

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
heapq.heapify(a)
heapq.heapify(b)
err = 1
for _ in range(N):
	if heapq.heappop(a) > heapq.heappop(b):
		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()

for i in range(n):
  if a[0] <= b[0]:
    del a[0]
    del b[0]
  else:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

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

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
#print(cnt)
a.sort()
b.sort()
'''
for i in range(n):
    if a[i] <= b[i]:
        if i == n - 1:
            if cnt > n-2:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()
    else:
        print('No')
        sys.exit()
'''
print('No')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

    A.sort()
    B2 = sorted(B)
    cnt = 0

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

    for i in range(N):
        if B[i] != B2[i]:
            cnt += 1

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    if max(B)<max(A):
        print(NO)
        return
    
    ## 完成形を作る
    B_tuple = []
    A_tuple = []
    for i in range(N):
        B_tuple.append((B[i],i))
        A_tuple.append((A[i],i))
    
    A_tuple.sort(key=lambda x: x[0])
    B_tuple.sort(key=lambda x: x[0])
    dif = 0
    for i in range(N):
        dif += abs(A_tuple[i][1]-B_tuple[i][1])
    
    if math.ceil(dif/2) <= N:
        print(YES)
    else:
        print(NO)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt = 0
for A,B in zip(As_ind,Bs_ind):
    if A[0] > B[0]:
        print("No")
        exit()
    else:
        if A[1] == B[1]:
            cnt = 1
if cnt > 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ar = list()
for n in range(N):
    ar.append([A[n],B[n]])
ar = sorted(ar, key=lambda x:x[1])
A = [x[0] for x in ar]
B = [x[1] for x in ar]
calc = max(A) <= max(B)
if not calc:
    print("No")
else:
    if N >= 2:
        count = 0
        meet = 0
        not_meet = 0
        for n in range(N):
            if A[n] <= B[n]:
                meet += 1
            else:
                not_meet += 1
        if meet >= 2:
            print("Yes")
        else:
            print("No")
    if 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()))

def swap(A,i,j):
  tmp = A[i]
  A[i] = A[j]
  A[j] = tmp
  
for i in range(N):
  
  a = [A[j] for j in range(i,N) if A[j] <= B[i] ]
  if len(a) == 0:
    print("No");exit()
  a.sort(reverse = True)
  swap(A,i,A.index(a[0]))

print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
count = 0
rechecklist=[]
for idx in range(len(A)):
    if A[idx] <= B[idx]:
        continue
    else:
        flg=False
        tmp = 10 ** 5
        tmpidx = -1
        for idy in range(len(A)):
            if (idx != idy and A[idx] <= B[idy] and A[idy] <= B[idx]):
                B[idx],B[idy] = B[idy],B[idx]
                count = count + 1
                flg = True
                break
            elif (idx != idy and A[idx] <= B[idy] and tmp > B[idy]):
                tmp = B[idy]
                tmpidx = idy
        if flg == False:
            if tmpidx == -1:
                count = N + 1
                break
            else:
                B[idx],B[tmpidx] = B[tmpidx],B[idx]
                count = count + 1
                if (idx > tmpidx):
                    rechecklist.append(tmpidx)
for idx in rechecklist:
    for idy in range(len(A)):
        flg=False
        if (idx != idy and A[idx] <= B[idy] and A[idy] <= B[idx]):
            B[idx],B[idy] = B[idy],B[idx]
            count = count + 1
    if flg == False:
        if tmpidx == -1:
            count = N + 1
            break
print("Yes" if N >= count else "No")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

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

for j in range(n):
    if a[j] > b[j]:
        cnt +=1
#print(cnt)
a.sort()
b.sort()
'''
for i in range(n):
    if a[i] <= b[i]:
        if i == n - 1:
            if cnt > n-2:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()
    else:
        print('No')
        sys.exit()
'''
print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = "Yes"
a.sort()
b.sort()
for (x,y) in zip(a,b):
  if x>y:
    ans = "No"
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  if a[i] > b[i]:
    ans2 += 1

a = sorted(a)
b = sorted(b)

for i in range(n):
  if a[i] > b[i]:
    print("No")
    ans += 1
    break
    
if ans2 > n-2 and ans == 0:
  print("No")
elif ans == 0:
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

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

a.sort()
b.sort()

for i in range(n-2):
    index = n-i-1
    max_a = a[index]
    max_b = b[index]
    if max_b < max_a:
        print('No')
        sys.exit()
    else:
        del a[index]
        del b[index]

for i in range(2):
    if a[i] > b[i]:
        print('No')
        sys.exit
print('Yes')

Submission status: Wrong Answer

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

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

print("Yes")

Submission status: Wrong Answer

Solution code:
print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
flg = 0
cnt = 0
for i in range(n):
    if al[i]<=bl[i]:
        cnt+=1

# if cnt < 2:
#     flg=1
    
al.sort()
bl.sort()

for i in range(n):
    if al[i]>bl[i]:
        flg=1

if flg==0:
    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()))
a1 = sorted(a)
b1 = sorted(b)
c = zip(a1, b1)

if all(x[0]<=x[1] for x in c):	
	if n == 2 and any(x[0]>x[1] for x in zip(a, b)):
		print("No")
	else:
		print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A=many_int()
B=many_int()

sortedA =sorted(A)
sortedB =sorted(B)
flg=True

for a,b in zip(sortedA,sortedB):
    if a>b:
        flg=False
        break
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

n = onem()

a = l()
b = l()

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

aa.sort()
bb.sort()
aa = s(aa)

kkk = {}

count = 0
for i in range(len(aa)):
    kkk[aa[i][0][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]
count = 0
for i in range(n):
    k = bb[i][1]
    if i >= kkk[k][0] and kkk[k][1] <= i:
        count += 0
    else:
        count += 1



if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aa[i][0][0] <= 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_s = a.copy()
b_s = b.copy()

a_s.sort()
b_s.sort()

c = 0
cc = 0

for i in range(n):
    if a[i] > b[i]:
        c += 1
    if a_s[i] > b_s[i]:
        print('No')
        cc = 1
        break

if n > 2 and c >= n-1:
    print('No')
    cc = 1

if cc == 0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

for a, b in zip(sorted(aa), sorted(bb)):
    if a > b:
        print('No')
        exit(0)

aa_s = sorted(aa)
bb_s = sorted(bb)
worst = True
for i in reversed(range(1, n)):
    if aa_s[i] <= bb_s[i-1]:
        worst = False
        break
if not worst:
    print('Yes')
    exit(0)

ba = sorted(zip(bb, aa))
aa2 = []
bb2 = []
for b, a in ba:
    bb2.append(b)
    aa2.append(a)
if sorted(aa2) == (aa2[1:] + aa2[:1]):
    print('No')
else:
    print('Yes')

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

#インデックス付きソート
#(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]
    temp = A[aindex]
    A[aindex] = A[bindex]
    A[bindex] = temp
    A3[aindex][0] = bindex
    A3[bindex][0] = aindex 


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

count = 0

for i, j in zip(A, B):
    if i < j:
        count += 1
A.sort(reverse=True)
B.sort(reverse=True)

swap = True
for i, j in zip(A, B):
    if i > j:
        swap = False
        break

if count <= N-2 and swap:
    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()
ans="Yes"
for i in range(n):
  if a[i]>b[i]:
    ans="No"
    break
print(ans)

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)

check = [a <= b for a, b in zip(A_, B_)]

if len(check) == sum(check):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A1=[int(s) for s in input().split()]
B1=[int(s) for s in input().split()]
A2=[(A1[i],i) for i in range(N)]
B2=[(B1[i],i) for i in range(N)]
A=sorted(A2)
B=sorted(B2)
for i in range(N):
  if B[i][0]<A[i][0]:
    print("No")
    break
else:
  for i in range(N-1):
    if B[i][0]>=A[i+1][0]:
      print("Yes")
      break
  else:
    for i in range(N):
      if A[i][1]==B[i][1]:
        print("Yes")
        break
    else:
      k=0
      for i in range(N-1):
        k=B[k][1]
        if k==0:
          print("Yes")
          break
      else:
        print("No")

Submission status: Wrong Answer

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

    arr1.sort()
    arr2.sort()
    for i in range(n):
        if arr1[i] > arr2[i]:
            print('No')
            return

    print('Yes')
        


main()

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()))
C = []
for i in range(N):
    C.append([A[i], B[i]])
C.sort()
C.sort(key=lambda x: x[1])
Count = 0
for i in range(N):
    if Count == N - 1:
        print('No')
        exit()
    if C[i][0] <= C[i][1]:
        continue
    for j in range(1, N-i):
        if C[i+j][0] <= C[i][1]:
            C[i][0], C[i+j][0] = C[i+j][0], C[i][0]
            Count += 1
            break
    else:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from queue import PriorityQueue

def readInts():
  return [int(s) for s in input().split(" ")]

def solve(N, A, B):
  zipped = sorted(zip(A, B), reverse=True)
  pq = PriorityQueue()
  for i, (a, b) in enumerate(zipped):
    pq.put((-1 * b, i))

  c = 0
  for i in range(N):
    if zipped[i][0] > zipped[i][1]:
      mb, k = pq.get()
      while k < i:
        mb, k = pq.get()
      b = -1 * mb
      if zipped[i][0] <= b:
        pq.put((-1 * zipped[i][1], k))
        zipped[k] = (zipped[k][0], zipped[i][1])
        c += 1
      else:
        return False
  return (c <= N - 2)

def main():
  N = readInts()[0]
  A = readInts()
  B = readInts()
  if solve(N, A, B):
    print('Yes')
  else:
    print('No')

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_sorted = sorted(a)
b.sort()

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

for i in range(n):
    if a_sorted[i] > b[i]:
        print('No')
        sys.exit()
if mergecount(a) <= n-2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
print('No')
print('Yes')

Submission status: Wrong Answer

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

sorta=sorted(a)
sortb=sorted(b)
gyaku=0

for i in range(n):
    if(a[i] > b[i]):
        gyaku+=1

    if(sorta[i] > sortb[i]):
        print("No")
        sys.exit()

if(gyaku <= n-2):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

n = onem()

a = l()
b = l()

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

aa.sort()
bb.sort()
aa = s(aa)

kkk = {}

count = 0
for i in range(len(aa)):
    kkk[aa[i][0][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]
count = 0
for i in range(n):
    k = bb[i][1]
    if i >= kkk[k][0] and kkk[k][1] <= i:
        count += 0
    else:
        count += 1



if count >= n-1:
    print("No")
else:
    for i in range(n):
        if not aa[i][0][0] <= bb[i][0]:
            print("No")
            exit()
    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()))
        
#print(a)
#print(b)

plist = []

for i in range(len(a)):
    if(a[i] == b[i]):
        plist.append(i)
        
for i in range(len(plist)-1,-1,-1):
    x = plist[i]
    a.pop(x)
    b.pop(x)
    
a.sort()
b.sort()

an = np.array(a)
bn = np.array(b)

#print(a)
#print(b)

if(len(an) == 0):
    ans = "Yes"
elif(len(an) > n-2):
    ans = "No"
else:
    flag = 0
    ans = "Yes"
    for i in range(len(an)):
        if(b[i] > a[i]):
            ans = "No"
            break
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(nn) for nn in input().split()]
b = [int(nn) for nn in input().split()]
asort = sorted(a)
bsort = sorted(b)
for aa, bb in zip(asort, bsort):
    if aa > bb:
        print('No')
        exit()
am = []
bm = []
for aa, bb in zip(a, b):
    if aa < bb:
        am.append(aa)
        bm.append(bb)

if len(am) <= n:
    print('Yes')
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)
D = sorted(B)



for i,v in enumerate(C):
    if v > D[i]:
        print('No')
        sys.exit()

cA =0
for i in range(N):
    if A[i] > B[i]:
        cA += 1
#print(cA)
if cA/2 > N-2:        
    print('No')
    sys.exit()
print('Yes')

Submission status: Wrong Answer

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

aa = sorted(a)
bb = sorted(b)

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

ab = []

for i in range(n):
    ab.append([a[i],b[i]])

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

for i in range(n):
    if aa[i] == ab[i][0]:
        print('Yes')
        exit()

print('No')