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:
from collections import Counter
from bisect import bisect_left, bisect_right

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    return N, A, B

def argmax(x):
    imax = 0
    for i in range(1, len(x)):
        if x[imax] < x[i]:
            imax = i
    return imax


def argsort(x):
    pairs = [(i, x[i]) for i in range(len(x))]
    pairs.sort(key=lambda a: a[1])
    return [a[0] for a in pairs]


def solve(N, A, B):
    key = argsort(A)
    A = [A[i] for i in key]
    B = [B[i] for i in key]
    # 高々2N種類の数字しかない
    # 「数」の代わりに「n番目に小さい数」を配列に持つ
    numbers = sorted(list(set(A) | set(B)))
    C = [bisect_left(numbers, A[i]) for i in range(N)]
    D = [bisect_left(numbers, B[i]) for i in range(N)]
    k = N - 2
    for i in range(N-1, -1, -1):
        if C[i] > D[i]:
            r = bisect_right(C, D[i])
            j = argmax(D[:r])
            # swap
            temp = D[j]
            D[j] = D[i]
            D[i] = temp
            k -= 1
            if k == 0:
                break
    for i in range(N):
        if C[i] > D[i]:
            return 'No'
    return 'Yes'

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Wrong Answer

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

ng_count = 0
for a, b in zip(A, B):
    if a > b:
        ng_count += 1
if ng_count * 2 > N - 2:
    print("No")
    sys.exit()

sorted_A = sorted(A)
sorted_B = sorted(B)
for a, b in zip(sorted_A, sorted_B):
    if a > b:
        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()))
C=sorted([[a,i+1] for i,a in enumerate(A)])
D=sorted([[b,i+1] for i,b in enumerate(B)])
E=[]
for i in range(n):
  if C[i][0]>D[i][0]:
    print("No")
    exit()
  elif C[i][1]>D[i][1]:
    E.append(C[i][1]-D[i][1])
  elif C[i][1]<D[i][1]:
    E.append(n+C[i][1]-D[i][1])
print("No" if len(set(E))==1 and len(E)==n and len(set(A))==n and len(set(B))==n else "Yes")

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)
f = sum(b_[i]<a_[i] for i in range(n))
if f:
    print("No")
    exit(0)
g = sum(b_[i-1]>=a[i] for i in range(1,n))
if g:
    print("Yes")
    exit(0)
da = dict()
for i in range(n):
    da[a_[i]] = i
ca = list(map(lambda x:da[x],a))
db = dict()
for i in range(n):
    db[b_[i]] = i
cb = list(map(lambda x:db[x],b))
cb2 = [None]*n
for i in range(n):
    cb2[ca[i]] = cb[i]
cnt = 1
c = cb2[0]
while c:
    c = cb2[c]
    cnt = 1
if cnt ==  n:
    print("No")
else:
    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

path = 0
visited = [False] * N
for i, a in enumerate(orderA):
    if visited[i]:
        continue
    visited[i] = True
    length = 0
    now = orderB[i]
    while now != a:
        now = orderA[now]
        visited[now] = True
        now = orderB[now]
        length += 1
        if length > N - 2:
            break
    path = max(path, length)

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

Submission status: Wrong Answer

Solution code:
import bisect

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


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

p.sort()
#print(p)

a.sort()
b.sort()


kanou=True
for i in range(n):
    ban=bisect.bisect_right(a,b[i])
    #print(ban)
    if(ban<=i):
        kanou=False


if(kanou):
    kasanari=False
    for i in range(n):
        if(a[i]==p[i][1]):
            kasanari=True
            break
    if(not kasanari):
        kanou=False
if(kanou):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

if max(A)>max(B):
  print('No')
else:
  sorted_A = deque(sorted(A))
  for i in range(n):
    if min(A)>B[i]:
      print('No')
      exit()
    sorted_A.popleft()
  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

path = 0
visited = [False] * N
for i, a in enumerate(orderA):
    if visited[i]:
        continue
    visited[i] = True
    length = 0
    now = orderB[i]
    while now != a:
        now = orderA[now]
        visited[now] = True
        now = orderB[now]
        length += 1
        if length >= N - 2:
            break
    path = max(path, length)

if path <= N - 2:
    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()))

ng_count = 0
for a, b in zip(A, B):
    if a > b:
        ng_count += 1
if ng_count / 2 > N - 2:
    print("No")
    sys.exit()

sorted_A = sorted(A)
sorted_B = sorted(B)
for a, b in zip(sorted_A, sorted_B):
    if a > b:
        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()
dekiru=1

for i in range(n):
	if a[i]>b[i]:
		dekiru=0
		break
if dekiru==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()))

s = 0
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        s +=1
if s >= N - 1:
    print('No')

else:
    A.sort()
    B.sort()

    s = 0
    for i in range(N):
        if A[i] <= B[i]:
            pass
        else:
            s +=1
    if s == 0:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

a.sort()
b.sort()

a_np = np.array(a)
b_np = np.array(b)

for i in a_np - b_np:
  if i<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()))

def merge_sort(arr):
    if len(arr) <= 1:
        return arr
    mid = len(arr) // 2

    left = arr[:mid]
    right = arr[mid:]

    left = merge_sort(left)
    right = merge_sort(right)
    return merge(left, right)
  
def merge(left, right):
    merged = []
    l_i, r_i = 0, 0
    while l_i < len(left) and r_i < len(right):
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged   
a=merge_sort(a)
b=merge_sort(b)
flag=1
for i in range(n):
  if a[i]<=b[i]:
    flag*=1
  else:
    flag*=0
    break
if flag==1:
  print('Yes')
else:
  print('No')

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

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

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

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


DIV = 998244353

def main():
    N = iRaw()
    As = isRaw()
    Bs = isRaw()
    AIs = [[a,idx] for idx,a in enumerate(As)]
    BIs = [[a, As[idx],idx] for idx, a in enumerate(Bs)]
    BIs.sort()
    aique = []
    isA_used = [0]*len(As) 
    
    for ai in AIs:
        heappush(aique,[ai[0],-Bs[ai[1]],ai[1]])
    
    nSwap = 0
    for bi in BIs:
        if bi[0]>=As[bi[-1]]:
            isA_used[bi[-1]]=1
        else:
            if bi[0]<aique[0][0]:
                return "No"
            else:
                isA_used[aique[0][2]] = 1
                As[bi[-1]], As[aique[0][2]] = As[aique[0][2]],As[bi[-1]]
                nSwap +=1
                heappop(aique)
        while len(aique)>0 and isA_used[aique[0][2]]==1:
            heappop(aique)
    if nSwap>N-2:
        return "No"
    return "Yes"

if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

s = 0
for i in range(N):
    if A[i] <= B[i]:
        pass
    else:
        s +=1
if s <= N - 1:
    print('No')

else:
    A.sort()
    B.sort()

    s = 0
    for i in range(N):
        if A[i] <= B[i]:
            pass
        else:
            s +=1
    if s == 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()))

t = sorted(a)
s = sorted(b)
for i in range(n):
    if t[i] > s[i]:
        print("No")
        exit()
        
b_min = 10**18
a_max = 0
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if b[i] < b_min:
            a_max = a[i]
            b_min = b[i]
            ind = i
        elif b[i] == b_min and a[i] > a_max:
            a_max = a[i]
            ind = i

if ind == -1:
    print("No")
    exit()

t = sorted(a[0:ind] + a[ind+1:])
s = sorted(b[0:ind] + b[ind+1:])
for i in range(n-1):
    if t[i] > s[i]:
        break
else:
    print("Yes")
    exit()
    
diff = 10**18
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if b[i] - a[i] < diff:
            diff = b[i] - a[i]
            ind = i

t = sorted(a[0:ind] + a[ind+1:])
s = sorted(b[0:ind] + b[ind+1:])
for i in range(n-1):
    if t[i] > s[i]:
        break
else:
    print("Yes")
    exit()
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 A[i] in tmp.keys():
      tmp[A[i]]=[]
    tmp[A[i]].append(B[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 
 # print(tmp)
  for i in range(N):
    print(A[i],B[i])
    if B[i] in tmp[A[i]]:
      print(B[i])
      print("Yes")
      return
  print("Yes")
      
main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

count = 0

flag = True

for x, y in zip(a, b):
  if x > y:
    count += 1

if count > n-2:
  flag = False

sa = sorted(a, reverse=True)
sb = sorted(b, reverse=True)

for x, y in zip(sa, sb):
  if x > y:
    flag = False
    break


if flag:
  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 = []

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

aaa.sort()
bb.sort()
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:
        count += 1



if count > n-1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

hoge = [a > b for a, b in zip(saa, sbb)]
fuga = [aa.index(a) == bb.index(b) for a, b in zip(saa, sbb)]
# (1,2)
# (2,1) NG
# (1,2,3)
# (2,1,3) OK
# (1,2,3)
# (2,3,1) NG
if any(hoge) or not any(fuga):
    print('No')
else:
    print('Yes')

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()
        
if a[1] > b[0]:
    if A[1] == a[0] and B[1] == b[0]:
        print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))

    # 既に条件満たしている時
    if(all(A[i]<=B[i] for i in range(n))):
        print("Yes")
        return

    C=[0]*n
    D=[0]*n
    for i,a in enumerate(A):
        C[i]=(a,i)
    C.sort()
    for i in range(n):
        j=C[i][1]
        D[i]=B[j]

    A.sort()
    B.sort()
    if(any(A[i]>B[i] for i in range(n))):
        print("No")
        return
    if(any(A[i+1]<=B[i] for i in range(n-1))):
        print("Yes")
        return

    # DがAの回転のときダメ
    idx=-1
    for i in range(n):
        if(A[i]>D[i]):
            idx=i
            break
    if(idx==-1):
        print("Yes")
        return
    if(D[idx:]+D[:idx]==B):
        print("No")
        return
    print("Yes")
resolve()

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    pt = []
    for i in range(N):
        pt.append([A[i], 0, i])
        pt.append([B[i], 1, i])
    pt.sort()
    count = 0
    visited = set()
    twist = 0
    for i in range(len(pt)):
        if pt[i][1] == 0:
            count += 1
            if pt[i][2] not in visited:
                visited.add(pt[i][2])
            else:
                twist += 1
        else:
            count -= 1
            if pt[i][2] not in visited:
                visited.add(pt[i][2])
        if count < 0 or twist > N-2:
            return "No"
    return "Yes"


if __name__ == '__main__':
    # main()
    print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

if max_a > max_b:
    print('No')
    exit()

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

c_a = sorted(Counter(A).items())
c_b = sorted(Counter(B).items())

idx = 0
total_a = 0
total_b = 0
len_c_a = len(c_a)
for k, v in c_b:
    while idx < len_c_a and c_a[idx][0] <= k:
        total_a += c_a[idx][1]
        idx += 1
    total_b += v
    if total_a < total_b:
        print('No')
        exit()
print('Yes')

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

if max(a) > max(b):
    print("No")
else:
    count =0
    success = True
    for i in range(n):
        if a[i] > b[i]:
            next_min_index = np.argmin(a[1+1:])
            a[i] , a[next_min_index] = a[next_min_index], a[i]
            if a[i] > b[i]:
                success = False
                break
            count+=1
    if (success ==False or count>n-2):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

a_sorted = sorted(a)
b_sorted = sorted(b)

for i in range(n-2):
    aidx = a.index(a_sorted[-1]) # a の max の idx
    bidx = b.index(b_sorted[-1]) # b の max の idx
    tmp = a[bidx]
    a[bidx] = a[aidx]
    a[aidx] = tmp# a の aidx 番目と bidx 番目を入れ替え
    if a[bidx] > b[bidx]:
        print('No')
        sys.exit()
    del a[bidx]
    del b[bidx]
    del a_sorted[-1]
    del b_sorted[-1]
    #print(a)
    #print(b)
if a[0] > b[0]:
    print('No')
    sys.exit()
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

def solve() :
    sA, tB = zip(*sorted(zip(A, B)))
    sB = sorted(B)
    
    for i in range(N) :
        if sA[i] > sB[i] :
            return 'No'
            
    for i in range(1, N) :
        if sA[i] <= sB[i-1] :
            return 'No'
    
    tB = [bisect_left(sB, tB[i]) for i in range(N)]
    pos = [0] * N
    for k, v in enumerate(tB) :
        pos[v] = k
    # print(tB)
    # print(pos)
    
    count = 0
    for i in range(N) :
        if pos[i] == i :
            continue
        j = pos[i]
        # print(i, j, pos[i], pos[j])
        pos[i], pos[j] = pos[j], pos[i]
        count += 1
        # print(pos)
    # print('swap', count)
    if count <= N - 2 :
        return 'Yes'
    else :
        return 'No'
    
print(solve())

Submission status: Wrong Answer

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

NO = "No"
YES = "Yes"
X = []
Y = []
BW = []

for i in range(N):
  if A[i] <= B[i]:
    BW.append([A[i], B[i]])
  else:
    X.append(A[i])
    Y.append(B[i])

if len(BW) == 0:
  print(NO)


X.sort()
Y.sort()

cnt = 0
L = []
for i in range(len(X)):
  if X[i - cnt] > Y[i]:
    L.append(Y[i])
    cnt += 1

P = X[len(X) - cnt:]

import heapq
pop = heapq.heappop
push = heapq.heappush
q  = []

BW.sort(key = lambda x: x[1], reverse = True)

cnt -= 1
bcnt = 0

MI = []
while bcnt < len(BW):
  if cnt == -1:
    break
  if P[cnt] <= BW[bcnt][1]:
    push(q, BW[bcnt][0])
    bcnt += 1
  else:
    if len(q) == 0:
      print(NO)
      exit()
    p = pop(q)
    MI.append(p)
    cnt -= 1

for i in range(len(L) - len(MI)):
  if len(q) == 0:
    print(NO)
    exit()
  p = pop(q)
  MI.append(p)

MI.sort()
L.sort()

for i in range(len(MI)):
  if L[i] > MI[i]:
    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()))
A=sorted(a,reverse=True)
B=sorted(b,reverse=True)
cnt=0
for i in range(n):
  if A[i]>B[i]:
    print('No')
    sys.exit()
  else:
    if a[i]<=b[i]:
      cnt+=1
if cnt>0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import copy

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')
        break
else:
    r = 10**9
    check = []
    for i in range(n):
        if 0 <= B[i] - A[i] < r:
            r = B[i] - A[i]
            m = i
    for i in range(n):
        if B[i] - A[i] == m:
            check.append(i)
    for idx in check:
        C = copy.deepcopy(A)
        D = copy.deepcopy(B)
        C.pop(idx)
        D.pop(idx)
        for c, d in zip(sorted(C), sorted(D)):
            if c > d:
                break
        else:
            print('Yes')
            break
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=a
bb=b
a.sort()
b.sort()
dekiru=1
onaji=0
issho=0
for i in range(n):
	if a[i]==aa[i]:
		onaji=1
if onaji==1:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("No")
	else:
		print("Yes")
		
else:print("No")
	# for i in range(n):
		# if aa[i]==bb[i]:
			# issho=1
			# memo=i
			# break
	# if issho==1:
		# a.remove(aa[memo])
		# b.remove(bb[memo])
		# for i in range(n):
			# if a[i]>b[i]:
				# dekiru=0
				# break
			# if dekiru==1:
				# print("Yes")
			# else:
				# print("No")
	# else:
		# print("No")

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
b_array = list(map(int, input().split()))
a_array = map(int, input().split())
a_based_b_array = [[0, 0] for _ in range(n)]
a_array = [(a, not (a < b)) for a, b in zip(a_array, b_array)]
b_array.sort()
#print(a_array)
#print(b_array)
flag = False
for a, j in a_array:
    i = bisect.bisect_right(b_array, a)
    if i != 0:
        a_based_b_array[i - 1][0 if j else 1] += 1
    else:
        flag = True
        break

ans = "Yes"
useable_a = [0, 0]
#print(flag,a_based_b_array)
if not flag:
    for i in reversed(range(n)):
        useable_a[0] += a_based_b_array[i][0]
        useable_a[1] += a_based_b_array[i][1]
        if useable_a[1] > 0:
            useable_a[1] -= 1
        else:
            if useable_a[0] > 0:
                flag=True
                useable_a[0] -= 1
            else:
                ans = "No"
        if not flag and useable_a[0] > 0:
            flag = True
    if flag:
        print(ans)
    else:
        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()))

c = []
d = []
total = 0
flag = 0
for i in range(n):
    if a[i]>b[i]:
        total +=1
        c.append(a[i])
        d.append(b[i])

c.sort()
d.sort()

for i in range(len(c)):
    if c[i]>d[i]:
        flag = 1
        
if flag == 1 or total > n-2:
    print("NO")
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 = []

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

aaa.sort()
bb.sort()
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 = -1
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:
        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
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ng_count = 0
for a, b in zip(A, B):
    if a > b:
        ng_count += 1
if ng_count > N - 2:
    print("No")
    sys.exit()

sorted_A = sorted(A)
sorted_B = sorted(B)
for a, b in zip(sorted_A, sorted_B):
    if a > b:
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
BA = sorted([(b, a) for a, b in zip(A, B)])
A = [a for b, a in BA]
B = [b for b, a in BA]


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


def f(x, y):
    if x[1] <= y[1]:
        return x
    else:
        return y


cnt = 0
ST = SegmentTree(list(enumerate(A)), f=f, ti=(-1, 10**10))
for i in range(N):
    now = ST.query(i, i + 1)
    if now[1] > B[i]:
        cnt += 1
        cand = ST.query(i + 1, N)
        if cnt < N - 1 and cand[1] <= B[i]:
            ST.update(cand[0], (cand[0], now[1]))
            ST.update(now[0], (now[0], cand[1]))
        else:
            print('No')
            exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=a
bb=b
a.sort()
b.sort()
dekiru=1
onaji=0
issho=0
for i in range(n):
	if a[i]==aa[i]:
		onaji=1
if onaji==1:
	for i in range(n):
		if a[i]>b[i]:
			dekiru=0
			break
	if dekiru==1:
		print("Yes")
	else:
		print("No")
		
else:print("No")
	# for i in range(n):
		# if aa[i]==bb[i]:
			# issho=1
			# memo=i
			# break
	# if issho==1:
		# a.remove(aa[memo])
		# b.remove(bb[memo])
		# for i in range(n):
			# if a[i]>b[i]:
				# dekiru=0
				# break
			# if dekiru==1:
				# print("Yes")
			# else:
				# print("No")
	# else:
		# print("No")

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
# import math


def main():
    n = getN()
    anums = getList()
    bnums = getList()

    asort = sorted(copy.copy(anums))
    bsort = sorted(copy.copy(bnums))

    for a, b in zip(asort, bsort):
        if a > b:
            print("No")
            return
    
    yaba_index = [-1]
    tmpyaba = 0
    for a, b in zip(asort[1:], bsort):
        if a > b:
            yaba_index.append(tmpyaba)
        else:
            yaba_index.append(yaba_index[-1])
        tmpyaba += 1

    for a,b in zip(anums, bnums):
        if a <= b:
            # 変えなくてよい
            aidx = bisect.bisect_left(asort, a)
            bidx = bisect.bisect_left(bsort, b)

            if aidx > yaba_index[bidx]:
                print("Yes")
                return

    print("No")


    # print(yaba_index)
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()))
C = 0
a = 0
b = 0
k = 0
for i  in range(0, N - 2):         
  if A[i] > B[i]:    
    A[i], B[i] = B[i], A[i]
    break
    
for j in range(N- 1, 0 ,-1):
  a += 10**j * A[k]
  b += 10**j * B[k]
  k += 1
  
if a <= b:
  print('Yes')
else:
  print('No')