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 bisect
from collections import defaultdict
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_B = sorted(B)
if all(a > b for a, b in zip(A, B)):  # N子動かす必要がある
    print("No")
    exit()

D = defaultdict(int)
for i, a in enumerate(A):
    ind = bisect.bisect_left(sort_B, a)
    D[i] = N-ind

for i, z in enumerate(zip(A, B)):
    a = z[0]
    b = z[0]
    if a <= b:
        if D[i] == 1:
            print("No")
            exit()
print("Yes")

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
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    for i in range(n):
        f = False
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_left(ca, b[i])
            for i in range(first, end):
                if ca[i] <= b[i]:
                    continue
                f = True
            if f:
                print("Yes")
                return
    print("No")

    return


def Dijkstra(num, start, vedge):

    dist = [float("inf") for i in range(num)]
    dist[0] = 0
    for i in range(num):
        du = dist[i]
        l = i
        for k, j in vedge[i]:
            if dist[j] <= du + k:
                continue
            for j in range(j, i - 1, -1):
                if dist[j] > du + k:
                    dist[j] = du + k
                    continue
                break
    return dist


#D
def D():
    n, m = LI()
    dist = [[] for i in range(n)]
    for _ in range(m):
        l, r, c = LI_()
        c += 1
        dist[l].append([c, r])
    for i in range(n):
        dist[i].sort()
    dist = Dijkstra(n, 0, dist)
    print(dist[n - 1] if dist[n - 1] != inf else -1)
    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()))

A.sort()
B.sort()

check = False
for x, y in zip(A, B):
    if x <= y:
        check = True
    
    else:
        check = False

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

Submission status: Wrong Answer

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

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

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}
A=[compression_dict[a] for a in A]
B=[compression_dict[a] for a in B]


SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

# BIT(BIT-indexed tree)
LEN=max(max(A),max(B))+10

BIT=[0]*(LEN+1)# 1-indexedなtree

def update(v,w):# index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in A:
    update(a,1)

BIT2=[0]*(LEN+1)# 1-indexedなtree

def update2(v,w):# index vにwを加える
    while v<=LEN:
        BIT2[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue2(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT2[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for a in B:
    update2(a,1)

#for i in range(1,4):
#    print(getvalue(i),getvalue2(i))

for i in range(N):
    a=A[i]
    b=B[i]

    if a>b:
        continue

    update(a,-1)
    update2(b,-1)

    #for i in range(1,4):
    #    print(getvalue(i),getvalue2(i))

    #print(getvalue(a),getvalue2(a),getvalue(b),getvalue2(b))

    if getvalue(a)>=getvalue2(a) and getvalue(b)>=getvalue2(b) and getvalue(a+1)>=getvalue2(a+1) and getvalue(b+1)>=getvalue2(b+1):
        print("Yes")
        sys.exit()
    else:
        update(a,1)
        update2(b,1)

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)

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

B.sort()
A_ = sorted(A)
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 > 0:
    print("Yes")
else:
    tmp = []
    for i in range(N):
        if [A_[i], A[i]] in tmp:
            tmp.pop(tmp.index([A_[i], A[i]]))
            print("Yes")
            exit(0)
        else:
            tmp.append([A[i], A_[i]])

    print("No")

Submission status: Wrong Answer

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

              
def mergeSort(arr): 
    if len(arr) >1: 
        mid = len(arr)//2 #Finding the mid of the array 
        L = arr[:mid] # Dividing the array elements 
        R = arr[mid:] # into 2 halves 

        mergeSort(L) # Sorting the first half 
        mergeSort(R) # Sorting the second half 

        i = j = k = 0
        
        # Copy data to temp arrays L[] and R[] 
        while i < len(L) and j < len(R): 
            if L[i] < R[j]: 
                arr[k] = L[i] 
                i+=1
            else: 
                arr[k] = R[j] 
                j+=1
            k+=1
        
        # Checking if any element was left 
        while i < len(L): 
            arr[k] = L[i] 
            i+=1
            k+=1
        
        while j < len(R): 
            arr[k] = R[j] 
            j+=1
            k+=1

def f():
    C = list(zip(A,B))
    mergeSort(C)
    #print(C)
    mergeSort(A)
    mergeSort(B)
    D = list(zip(A, B))
    #print(D)
    
    E = []
    for (a, c), (_, d) in zip(C, D):
        if c != d:
            E.append((a,c))
    #print(E)
    
    for a,b in D:
        if a > b:
            return 'No'
        
    if len(E)-1 > N-2:
        return 'No'
    
    return 'Yes'
print(f())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(map(int,input().split())))
for i in range(n):
  if a[i]>b[i]:
    print("No")
    break
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:


if __name__ == "__main__":
    N = int(input())
    A = input().split()
    B = input().split()
    A_sort = sorted(A)
    B_sort = sorted(B)
    for i in range(N):
        if A[i] >= B[i]:
            print("No")
            exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
import bisect
from collections import defaultdict
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_A = sorted(A)
sort_B = sorted(B)
if all(a > b for a, b in zip(A, B)):  # N子動かす必要がある
    print("No")
    exit()

D = defaultdict(int)
for i, a in enumerate(A):
    ind = bisect.bisect_left(sort_B, a)
    D[a] = N-ind

for i, z in enumerate(zip(A, B)):
    a = z[0]
    b = z[0]
    if a <= b:
        if D[a] == 1:
            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 = 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}
c = 0
for a, b in zip(A, B):
    if a == b:
        print("Yes")
        exit()
    if a <= b:
        c += 1
    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=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a1=sorted(a)
b1=sorted(b)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        exit()
cnt=0
for i in range(n):
    if a[i]>b[i]:
        cnt+=1
    elif a[i]<b[i]:
        cnt-=1
print("Yes" if cnt<n//2 else "No")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A2 = sorted(A)
    B2 = sorted(B)
    count = 0
    for i in range(n):
        if B[i] < A[i]:
            count += 1
    if count <= n-2:
        for i in range(n):
            if B2[i] - A2[i] < 0:
                print('No')
                exit()
        else:
            print('Yes')
            exit()
    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(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>1.5:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
from bisect import bisect_left, bisect_right
from collections import deque

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)]
    d_argsorted = deque(list(argsort(D)))
    k = N - 2
    for i in range(N-1, -1, -1):
        if C[i] > D[i]:
            r = bisect_right(C, D[i])  # O(logN)
            j = N + 1
            while j >= i:
                j = d_argsorted.pop()
                if len(d_argsorted) == 0:
                    return 'No'
            if C[i] > D[j]:
                return 'No' 
            # 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:
# coding: utf-8
import numpy as np
import bisect as bs


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    B = list(map(int, args[2].split()))

    sA = sorted(A)
    sB = sorted(B)

    ret = all(np.greater_equal(np.array(sB), np.array(sA)))

    ab = sorted(zip(A, B))
    sA, uB = zip(*ab)
    uB = list(uB)
    count = 0
    for i in range(n-1):
        if uB[i] >= uB[i+1]:
            for j in range(i+1, n):
                if uB[i] >= uB[j]:
                    uB[i], uB[j] = uB[j], uB[i]
                    count += 1
                    break

    ret = ret and (n-2 >= count)

    return 'Yes' if ret else 'No'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left

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

a = sorted(A)
b = sorted(B)

for i in range(N):
    if a[i] > b[i]:
        print("No")
        sys.exit()
        
        
for i in range(N):
    if A[i] <= B[i]:
        l = bisect_left(b,B[i])
        r = bisect_left(b,B[i]+1) - 1 
        if a[l] <= A[i] <= a[r]:
            print("Yes")
            sys.exit()

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
ans=0
for i in range(N):
    if A[i]>B[i]:
        ans+=1

if ans>N-2 or g==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()))

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

a_.sort()
b_.sort()
for i in range(n):
    if a_[i][0] == b_[i][0]:
        print('Yes')
        exit()
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
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:
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    ABs=list(zip(sorted(A),sorted(B)))
    for a,b in ABs:
        if a>b:
            return 'No'
    A=list(zip(sorted(A),range(1,n+1)))
    B=list(zip(sorted(B),range(1,n+1)))
    for (a,i),(b,j) in zip(A,B):
        if i==j:
            return 'Yes'
    return 'No'
    
if __name__=='__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from sys import exit

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

aa = [t[1] for t in sorted(zip(A, B), key=itemgetter(1, 0))]

a = list(sorted(A))
b = list(sorted(A))

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

if c == 0:
    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()

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)

Ac = A[:]
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,Ac[bindex])
    A3[p1][0] = i


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

Submission status: Wrong Answer

Solution code:
import bisect
import sys
from collections import defaultdict

input = sys.stdin.readline


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

        sorted_B = sorted(B)

        index_dict = defaultdict(list)
        for i in range(N):
            index_dict[B[i]].append(i)

        cnt = 0
        i = 0
        while i < N:
            if A[i] <= B[i]:
                i += 1
                continue
            else:
                index = bisect.bisect_left(sorted_B, A[i])
                if index >= N:
                    print('No')
                    exit()
                else:
                    cnt += 1
                    swap_target = index_dict[sorted_B[index]][-1]
                    A[i], A[swap_target] = A[swap_target], A[i]

                i = min(i + 1, swap_target)

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

        print('Yes')
# Run main
if __name__ == '__main__':
    AtCoder().main()

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
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    for i in range(n):
        if a[i] < b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_left(ca, b[i])
            for i in range(first, end):
                if ca[i] <= b[i]:
                    continue
                break
            else:
                print("Yes")
                return
    print("No")

    return


def Dijkstra(num, start, vedge):

    dist = [float("inf") for i in range(num)]
    dist[0] = 0
    for i in range(num):
        du = dist[i]
        l = i
        for k, j in vedge[i]:
            if dist[j] <= du + k:
                continue
            for j in range(j, i - 1, -1):
                if dist[j] > du + k:
                    dist[j] = du + k
                    continue
                break
    return dist


#D
def D():
    n, m = LI()
    dist = [[] for i in range(n)]
    for _ in range(m):
        l, r, c = LI_()
        c += 1
        dist[l].append([c, r])
    for i in range(n):
        dist[i].sort()
    dist = Dijkstra(n, 0, dist)
    print(dist[n - 1] if dist[n - 1] != inf else -1)
    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()))
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))
ch=0
for i in B:
	if i < A[ch]:
		print('No')
		exit()
	ch+=1
print('Yes')

Submission status: Wrong Answer

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

    for i in range(n):
        aa = a[:i] + a[i+1:]
        bb = b[:i] + b[i+1:]
        aa.sort()
        bb.sort()
        bl = True
        for aae, bbe in zip(aa, bb):
            if aae > bbe:
                bl = False
                break

        if bl:
            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()))
ans = 0
ans2 = 0
ls = []
ls2 = []
for i in range(n):
  if a[i] > b[i]:
    ls.append(a[i])
    ls2.append(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
    
t = 0
for i in ls:
  if i in ls2:
    t += 1
    break
    
    
if ans2 > n-2 and ans == 0 and t == 0:
  print("No")
elif ans == 0:
  print("Yes")

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()]
a1=sorted(a)
b1=sorted(b)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        exit()
cnt=0
for i in range(n):
    if a[i]>b[i]:
        cnt+=1
    elif a[i]<b[i]:
        cnt-=1
print("Yes" if cnt<n-2 else "No")

Submission status: Wrong Answer

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

for a, b in zip(A, B):
    if a <= b:
        break
else:
    print('No')
    exit()

A.sort()
B.sort()

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

Submission status: Wrong Answer

Solution code:
import random
print('Yes' if random.randrange(0, 10) % 2 == 0 else 'No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [b[i]-a[i] for i in range(n)]
l = len(list(filter(lambda x:x<0,d)))
a = sorted(a)
b = sorted(b)
ans = 'Yes'
for i in range(n):
  if b[i] - a[i] < 0:
    ans = 'No'
if l > n / 2:
  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)

Ac = A[:]
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,Ac[bindex])
    p2 = bisect_left(A2,Ac[aindex])
    A3[p1][0] = p2
    A3[p1][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=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
a1=sorted(a)
b1=sorted(b)
for i in range(n):
    if a1[i]>b1[i]:
        print("No")
        exit()
cnt=0
for i in range(n):
    if a[i]>b[i]:
        cnt+=1
    elif a[i]<b[i]:
        cnt-=1
print("Yes" if cnt<n-1 else "No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
a = []
b = []
for i in range(0, n):
    if aa[i] != bb[i]:
        a.append(aa[i])
        b.append(bb[i])
aa = sorted(a)
bb = sorted(b)
flag = 1
for i in range(0, len(aa)):
    if aa[i] > bb[i]:
        flag = 0
        break
if flag == 1:
    count = 0
    for i in range(0, len(a)):
        if a[i] > b[i]:
            count += 1
        if count // 2 > n - 2:
            flag = 0
            break

if flag == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
print("yes")