Problem:


Score : 600 points

Problem Statement

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

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

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

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

Sample Output 3

Yes



Sample input:
3
1 3 2
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:
import sys
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(1)
        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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
asl=sorted(al)
bsl=sorted(bl)
for i in range(n):
    if asl[i]>bsl[i]:
        print('No')
        break
else:
    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

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

Submission status: Wrong Answer

Solution code:
import bisect

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

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):
    print("Yes")
else:
    print("No")

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(1)
        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=0
    for i in range(n):
        if(A[i]>D[i]):
            idx=i
            break
    if(D[idx:]+D[:idx]==B):
        print("No")
        return
    print("Yes")
resolve()

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

L = []
for i in range(n):
  L.append([A[i], B[i]])
L.sort(key=lambda x: x[1])
sB = [i[1] for i in L]
#print(sB)

from bisect import bisect_left as bl
import sys
counter = 0
for i in range(n):
  if L[i][0] > L[i][1]:
    left = bl(sB, L[i][0])
    #print(L[i][1], left)
    for j in range(left, n):
      if L[j][0] <= L[i][1]:
        L[i][0], L[j][0] = L[j][0], L[i][0]
        counter += 1
        break
    else:
      print("No")
      sys.exit()
else:
  if counter <= n - 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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

flg = True
for i in range(N):
    if A[i] > B[i]:
        flg = False

if flg:
    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()

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

reverse=0
for i,n in zip(a,b):
	if i>n:
		reverse+=1


a.sort()
b.sort()
D=True
for i,n in zip(a,b):
	if i>n:
		D=False
		break

if D and reverse<=N-2 and reverse%2==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()))

for a, b in zip(sorted(A), sorted(B)):
    if a > b:
        print('No')
        break
else:
    r = 10**9
    for i in range(n):
        if 0 <= B[i] - A[i] < r:
            r = B[i] - A[i]
            c = i
    A.pop(c)
    B.pop(c)
    for a, b in zip(sorted(A), sorted(B)):
        if a > b:
            print('No')
            break
    else:
        print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

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

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

print(yes)
exit(0)

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

Submission status: Wrong Answer

Solution code:
import bisect

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

a.sort()
b.sort()

print(a)
print(b)

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


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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = collections.Counter(A)
C = sorted(C.items(), key=lambda x:x[0],reverse=True)

for i in range(N):  
  for j in range(len(C)):
    c = list(C[j])    
    if c[0] <= B[i] and c[1] != 0:
      c[1] -= 1
      C[j] = c
      break
    if j == len(C)-1:
      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()))

count = 0
index = 0
while count <= n-2:
    max_a = max(a)
    max_b = max(b)
    index_a = a.index(max_a)
    index_b = b.index(max_b)
    if index_a != index_b:
        count = count + 1
    if max_b < max_a:
        print('No')
        sys.exit()
    else:
        a[index_a] = a[index_b]
        del a[index_b]
        del b[index_b]

    if len(a) == 0:
        print('Yes')
        sys.exit()

for i in range(len(a)):
    if a[i] > b[i]:
        print('No')
        sys.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()))

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

gyaku=0
gyaku_a=[]
gyaku_b=[]

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

    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 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()))
A_, B_=sorted(A), sorted(B)
flag=True
for i in range(N):
  if A_[i]>B_[i]:
    flag=False
    break
if not flag:
  print("No")
else:
  C=[(A[i], B[i]) for i in range(N)]
  C.sort(key=lambda x:(x[1], x[0]))
  A=[C[i][0] for i in range(N)]
  flag=False
  if A[0]!=A_[-1]:
    flag=True
  else:
    for i in range(1, N):
      if A[i]!=A_[i-1]:
        flag=True
        break
  if flag:
    print("Yes")
  else:
    print("No")
  '''
  ans=0
  for i in range(N):
    minv=A[i]
    mini=i
    if A[i]==A_[i]:
      continue
    for j in range(i+1, N):
      if A[mini]>A[j]:
        minv=A[j]
        mini=j
    if mini!=i:
      ans+=1
      A[i], A[mini]=A[mini], A[i]
    else:
      break
  if ans<=N-2:
    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()]
calc = max(A) <= max(B)
if not calc:
    print("No")
else:
    count = 0
    for n in range(N):
        if A[N-1-n] > B[N-1-n]:
            dist = float('inf')
            index = float('inf')
            for m in range(n,N):
                if B[N-1-n]-A[N-1-n-m] >= 0:
                    if dist > B[N-1-n]-A[N-1-n-m]:
                        dist = B[N-1-n]-A[N-1-n-m]
                        index = N-1-n-m
            if index <= N-1-n:
                tmp = A[N-1-n]
                A[N-1-n] = A[index]
                A[index] = tmp
                count += 1
    if count <= N-2:
        print("Yes")
    else:
        print("No")

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.sort()
b.sort()
for i in range(n):
    am = a[-1]
    bm = b[-1]
    if am <= bm:
        del a[-1]
        del b[-1]
    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()))

counter = 0
for i in range(N):
    if A[i] > B[i]:
        counter += 1

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

A = sorted(A)
B = sorted(B)

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

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
if g==0:
    _A=[]
    for i,a in enumerate(A):
        _A.append((i,a))
    _A.sort(key=lambda x:x[1])
    index=[]
    for i in range(N):
        index.append(_A[i][0])
    for i in range(1,N):
        if index[i]<index[i-1]:
            ans+=i-index[i]
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_min = 10**18
ind = -1
for i in range(n):
    if a[i] <= b[i]:
        if a[i] < a_min:
            a_min = a[i]
            ind = i

if ind == -1:
    print("No")
    exit()
a = sorted(a[0:ind] + a[ind+1:])
b = sorted(b[0:ind] + b[ind+1:])

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

print("Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect

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

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

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

    print('Yes')

    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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]))


if len(set(aa)) < n:
    print('Yes')
    exit()

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

from collections import defaultdict
d = defaultdict(int)

for i in range(n):
    d[aa[i]] += i

abd = [0]*n

for i in range(n):
    abd[i] = d[ab[i][0]]

for i in range(n):
    if abd[abd[i]] == i:
        print('Yes')

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

d=[]
for i in range(N):
    e=B[i]-A[i]
    if e<0:
        d.append(-e)
        
if sum(d)>0:
    print('No')
else :
    print('Yes')

Submission status: Wrong Answer

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

import sys
n = int(input())

al = list(map(int,input().split()))
bl = list(map(int,input().split()))

for a,b in zip(sorted(al),sorted(bl)):
    if b-a < 0:
        print("No")
        sys.exit()
        
for a,b in zip(al,bl):
    if b -a >= 0:
        print("Yes")
        sys.exit()
        
for i in range(n):
    for j in range(i+1, n):
        if bl[i] - al[j] >= 0 and bl[j] - al[i] >= 0:
            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(" ")))

reverse=0
for i,n in zip(a,b):
	if i>n:
		reverse+=0.5
		

a.sort()
b.sort()
D=True
for i,n in zip(a,b):
	if i>n:
		D=False
		break

if D and reverse<=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()))

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

gyaku=0
gyaku_a=[]
gyaku_b=[]

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

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

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

Submission status: Wrong Answer

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

count = 0
if max(a) > max(b) or min(a) > min(b):
    print('No')
else:
    for i in range(n):
        if a[i] > b[i]:
            count+=1
    if count%2 == 0 or count == 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()))
A_ , B_ = A,B

A_.sort()
B_.sort()

#すべての整数に対して、A[i] <= B[i]を満たすか確認
count = 0;
for i in range(N):
  if A_[i] > B[i]:
    count += 1
print(count)
#入れ替え操作がN-2回まででできる確認

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lista = list(map(int,input().split()))
listb = list(map(int,input().split()))

count = 0
#現在満たしている数を数える
for i in range(n):
    if lista[i] <= listb[i]:
        count += 1
#現在満たしている数が1だけならダメ
if count == 1:
    print("No")
    exit()

#ここは必須条件
lista.sort()
listb.sort()
for i in range(n):
    if lista[i] > listb[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()))
a_s = sorted(a)
b_s = sorted(b)
ans = 'Yes'
for i in range(n):
    if a_s[i]>b_s[i]:
        ans = 'No'
        break
if ans == "Yes":
    er_co = 0
    for i in range(n):
        if a[i]>b[i]:
            er_co += 1
    if er_co > n-2:
        ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)


def solve(N,A,B):
    A = sorted(A)
    B = sorted(B)

    for a,b in zip(A,B):
        if a > b:
            return False

    return True


def main():
    N = int(input())
    A = list(map(int, input().split())) # 操作可能
    B = list(map(int, input().split()))

    if solve(N,A,B):
        print("Yes")
    else:
        print("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()))

A_sort = sorted(A)
B_sort = sorted(B)


from collections import defaultdict
default_A = defaultdict(set)
default_A_risou = defaultdict(set)
default_B = defaultdict(set)
default_B_risou = defaultdict(set)


if any([a>b for  a,b in zip(A_sort,B_sort)]):
  print("No")
else:
  S_AB_sorted = set((a,b) for a,b in zip(A_sort,B_sort))
  for a,b in zip(A_sort,B_sort):
    default_A_risou[a] |= {b}
    default_B_risou[b] |= {a}
    
  S_AB = set((a,b) for a,b in zip(A,B))
  for a,b in zip(A,B):
    default_A[a] |= {b}
    default_B[b] |= {a}
  
  
  if len(S_AB & S_AB_sorted) > 0:
    print("Yes")
  else:
    # 存在するような組み合わせが一つでも作れればいい
    # B側から見た,本来結合したい相手の実際の結合相手に
    # Aの理想の結合相手が含まれているか
    for a,b in zip(A,B):
      # print([default_A[b_set] for b_set in default_B_risou[b]])
      all_set = set()
      for b_set in default_B_risou[b]:
        all_set |= default_A[b_set]
        
      if default_A_risou[a] & all_set:
        print("Yes")
        break
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
n,A,B=open(0);*A,=map(int,A.split());*B,=map(int,B.split())
j=[a>b for a,b in zip(A,B)].count(True)
A.sort();B.sort()
print("YNeos"[(j>int(n)-2)&all(a<=b<=c<=d for a,b,c,d in zip(A,B,A[1:],B[1:]))|any(a>b for a,b in zip(A,B))::2])

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:
    count = 0
    for n in range(N):
        if A[N-1-n] > B[N-1-n]:
            dist = float('inf')
            index = float('inf')
            for m in range(n,N):
                if B[N-1-n]-A[N-1-n-m] >= 0:
                    if dist > B[N-1-n]-A[N-1-n-m]:
                        dist = B[N-1-n]-A[N-1-n-m]
                        index = N-1-n-m
            if index <= N-1-n:
                tmp = A[N-1-n]
                A[N-1-n] = A[index]
                A[index] = tmp
                count += 1
    if count <= N-2:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]


def detection (a,b):
    for i in range(len(a)-1):
        if a[i]-b[i]>0:
            print("No")
            sys.exit()
    print("Yes")

if min(a)-min(b)>0:
    print("No")
    sys.exit()
else:
    for i in range(n-2):
        del a[a.index(max(a))]
        del b[b.index(max(b))]

detection(a,b)

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 c == n:
    print('No')
    cc = 1

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

Submission status: Wrong Answer

Solution code:
from sys import exit

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

print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

    array_a = np.array(sorted(A))
    array_b = np.array(sorted(B))

    distances = array_b - array_a

    result = 'Yes'
    if sum(distances < 0) > 0:
        result = 'No'

    print(result)


if __name__ == '__main__':
    answer()

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])
        pt.append([B[i], 1])
    pt.sort()
    count = 0
    for i in range(len(pt)):
        if pt[i][1] == 0:
            count += 1
        else:
            count -= 1
        if count < 0:
            return "No"
    return "Yes"


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

Submission status: Wrong Answer

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

reverse=0
for i,n in zip(a,b):
	if i>n:
		reverse+=1
		

a.sort()
b.sort()
D=True
for i,n in zip(a,b):
	if i>n:
		D=False
		break

if D and reverse<=N-2:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A.sort()
B.sort()
if np.where( (B - A) >= 0, 1, 0).sum() >= N:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]*n
b=[]*n
a=list(map(int,input().split(" ")))
b=list(map(int,input().split(" ")))
aso=sorted(a)
bso=sorted(b)
ans=True
for i in range(n):
    if aso[i]>bso[i]:ans=False
cnt=0
for i in range(n):
    if a[i]>b[i]:cnt+=1
if cnt>n-2:ans=False
if ans:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))

def maxminsumNum(list):
    max = 0
    min = 1000000000
    sum = 0
    for n in list:
        sum += n
        if (max < n):
            max = n
        if (n < min):
            min = n
    return max, min, sum

maxA, minA, sumA = maxminsumNum(listA)
maxB, minB, sumB = maxminsumNum(listB)

if (maxA > maxB | minA > minB | sumA > sumB):
    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()))
cnt = 0

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

a.sort()
b.sort()

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

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()))
A_mat = np.array(A)
B_mat = np.array(B)
C_mat = B_mat - A_mat
C = C_mat.tolist()
x = 10 ** 10
num = -1
for i in range(len(C)):
    if 0 <= C[i] < x:
        x = C[i]
        num = i
if x == 10 ** 10 and num == -1:
    print('No')
else:
    A.pop(num)
    B.pop(num)
    A.sort()
    B.sort()
    A1_mat = np.array(A)
    B1_mat = np.array(B)
    C1_mat = B1_mat - A1_mat
    if np.all(C1_mat >= 0):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = rli()
    lb = rli()
    ll = []
    pb = []
    for i in range(n):
        ll.append([la[i], lb[i]])
    ll.sort()
    for i in range(n):
        pb.append([ll[i][1], i])
    pb.sort()
    pc = [0 for _ in range(n)]
    for i in range(n):
        pc[pb[i][1]] = i
    # print(pb)
    # print(pc)

    la.sort()
    lb.sort()
    for i in range(n):
        if la[i] > lb[i]:
            print("No")
            return

    cnt = 0
    # print(ll)
    for i in range(n):
        j = pc[i]
        while i != j:
            if ll[i][0] != ll[j][0] and ll[i][1] != ll[j][1]:
                cnt += 1
            ll[i][1], ll[j][1] = ll[j][1], ll[i][1]
            pc[i], pc[j] = pc[j], pc[i]
            # print(i, j, ll[i], ll[j])
            j = pc[i]
    # print(ll)
    if cnt <= n-2:
        print("Yes")
    else:
        if cnt == n-1:
            print("Yes")
        else:
            print("No")
    

    # print('Yes')


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()))
counter = 0
for i in range(n):
    if B[i]+1==A[i]:
        counter += 1
if counter >= n-1:
    print('No')
    sys.exit()
else:
    Ar = sorted(A)
    Br = sorted(B)
    for i in range(n):
        if Br[i] < Ar[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()

d=[]
for i in range(N):
    e=B[i]-A[i]
    if e<0:
        d.append(e)
        
if sum(d)>0:
    print('No')
else :
    print('Yes')

Submission status: Wrong Answer

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

import sys
n = int(input())

al = list(map(int,input().split()))
bl = list(map(int,input().split()))

for a,b in zip(sorted(al),sorted(bl)):
    if b-a < 0:
        print("No")
        sys.exit()
        
for a,b in zip(al,bl):
    if b -a >= 0:
        print("Yes")
        sys.exit()
        
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()))
cnt = 0

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

a.sort()
b.sort()

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def solve():
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    Cs = sorted(As)
    Ds = sorted(Bs)

    for A, B in zip(Cs, Ds):
        if A > B:
            return False

    for i in range(N-1):
        if Cs[i] <= Ds[i+1] and Cs[i+1] <= Ds[i]:
            return True

    ABs = [(A, B) for A, B in zip(As, Bs)]
    ABs.sort(key=itemgetter(1))
    As = [A for A, B in ABs]
    Bs = [B for A, B in ABs]

    iAs = list(range(N))
    iAs.sort(key=lambda iA: As[iA])
    for i in range(N-2):
        if As[i] <= Bs[i]:
            return True
        As[i], As[iAs[i]] = As[iAs[i]], As[i]

    if As[N-2] <= Bs[N-2] and As[N-1] <= Bs[N-1]:
        return True
    else:
        return False

if solve():
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

n=int(input())
list_a=np.sort(list(map(int,input().split())))
list_b=np.sort(list(map(int,input().split())))

print(list_a)
print(list_b)

list_diff=list_b - list_a
for value in list_diff :
    if (value<0) :
        print('No')
        exit()

print('Yes')