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: Runtime Error

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 = Counter(A)
c_b = Counter(B)

list_a = [0] * (max_b + 1)
for k, v in c_a.items():
    list_a[k:] = list(map(lambda x: x + v, list_a[k:]))

list_b = [0] * (max_b + 1)
for k, v in c_b.items():
    list_b[k] = v

total_v = 0
for k, v in enumerate(list_b):
    if v == 0:
        continue
    total_v += v
    if list_a[k] < total_v:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
answer = "Yes"
for i in N:
  if A[i-1] < B[i-1]:
    answer = "No"
print(answer)

Submission status: Runtime Error

Solution code:
diff,zeros=[],[]
for i in range(N):
    dif = sorted(B)[i]-sorted(A)[i]
    zero = B[i]-A[i]
    diff.append(dif)
    zeros.append(zero)

l_zero = [i for i in zeros if i < 0]
l_diff = [i for i in diff if i >= 0]
if (len(l_diff) == N) and (len(l_zero) <= N-2):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

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 = Counter(A)
c_b = Counter(B)

list_a = [0] * (max_b + 1)
for k, v in c_a.items():
    if k > max_b:
        print('No')
        exit()
    list_a[k:] = list(map(lambda x: x + v, list_a[k:]))

total_v = 0
for k, v in sorted(c_b.items()):
    total_v += v
    if list_a[k] < total_v:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

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

i = j = 0
c = {}
d = {}
cnt = 0
while i<n and j<n:
    bi = bb[i]
    c[bi] = i
    while j<n and aa[j]<=bi:
        j += 1
    d[bi] = j
    i += 1

if any(d[bb[i]] < i+1 for i in range(n)):
    print("No")
    exit()

from bisect import bisect_left
ans = False
for i in range(n):
    bi = b[i]
    ai = a[i]
    if ai>bi:
        continue
    j = bisect_left(bb, ai)
    bj = bb[j]
    if bj==bi or d[bj] > c[bj]+1:
        ans = True
        break
if ans:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
answer = "Yes"
for i in range(0,N):
  if A[i] < B[i]:
    answer = "No"
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split())).sort()
answer = "Yes"
for i in range(0,N):
  if A[i] < B[i]:
    answer = "No"
print(answer)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

N = int(input())
D = list(map(int, input().split()))
max_D = max(D)

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx < 2:
        if tree == 0:
            count = 0
    else:
        count *= tree_list[idx - 1]**tree
print(count)

Submission status: Runtime Error

Solution code:
import os

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
n=0
for i in range(N):
  if A[i]>B[i]:
    n+=1
if n>N-2:
  print('No')
else:  
  m=max(max(A),max(B))
  a=[0]*m
  b=[0]*m
  for i in range(N):
    a[A[i]-1]+=1
    b[B[i]-1]+=1
  a_count=0
  b_count=0
  flag=True
  for i in range(m):
    a_count+=a[i]
    b_count+=b[i]
    if a[i]<b[i] and a_count<b_count:
      print('No')
      flag=False
  if flag:
    print('Yes')

Submission status: Runtime Error

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 B[i] < A[i]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Runtime Error

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

import heapq
heapq.heapify(a)
if heapq.heappop(A) > heapq.heappop(B):
  print('No')
  exit()
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
import numpy as np

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

AA = np.array(A)
BB = np.array(B)

#確認
sortC = np.array(sorted(B)) - np.array(sorted(A))
outrange = 0
for i in sortC:
  if i < 0:
    outrange += 1
if outrange >0:
  print("No")
  exit()

mainus = BB-AA
negative = 0
for i in mainus:
  if i < 0:
    negative += 1

if ceil(negative//2) =< n-2:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
c=[0]*n
ans=0
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(2,n-1):
    if c[j+1]!=0 and c[j]==0:
      ans=0
      break      
    elif c[j]==0 and c[j+1]==0:
      ans+=0
    else:
      ans*=c[j]**c[j-1]
      
  if c[n-2]==0　and c[n-1]!=0:
      ans=0
  elif c[n-2]==0 and c[n-1]==0:
    ans+=0
  elif:c[n-1]==0:
    ans+=0
  else:
    ans*=c[n-1]**c[n-2]
      
  print(int(ans%998244353))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
sA,sB=sorted(A),sorted(B)
data=[[a,b] for a,b in zip(sA,sB) if b>=a]
if  len(data)!=N:
    print("No")
    exit()
flag=[[a,b] for a,b in zip(A,B) if b>=a]




        exit()

A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
for i in range(N):
    for m in range(m,N-i-1):
        if B[i+m]>=A[i]:
            for a1,b1 in flag:
                if B[i+m]==b,A[i]==a1:
                    print("Yes")
                    exit()
print("No")

Submission status: Runtime Error

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


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

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

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

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

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


if __name__ == '__main__':
    main()

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
c=0
n=int(input())
ar=sorted(l_i())
br=sorted(l_i())
for i in range(n):
    if(ar[i]<=br[i]):
        c=c+1
    else:
        print('NO')
        break
if(c==n):
    print('YES')

Submission status: Runtime Error

Solution code:
c=0
n=int(input())
ar=sorted(l_i())
br=sorted(l_i())
print(ar)
print(br)
for i in range(n):
    if(ar[i]<=br[i]):
        c=c+1
    else:
        print('NO')
        break
if(c==n):
    print('YES')

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
s = list(set(a))
d = dict()
for i, x in enumerate(s):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(0)
al = [d[x[0]] for x in l]
cnt = 0
t = al[0]
while t != 0:
    t = al[t]
    cnt += 1
if cnt == n - 1:
    print('No')
else:
    print('Yes')
    exit(1)

Submission status: Runtime Error

Solution code:
_,*D=map(int,open(0).read().split());a=D[0]==0;M=[0]*-~max(D)
for d in D:M[d]+=1
for m,n in zip(M,M[1:]):a=a*m**n%998244353
print((M[0]<2)*a)

Submission status: Runtime Error

Solution code:
import os

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
m=max(max(A),max(B))
a=[0]*m
b=[0]*m
for i in range(N):
  a[A[i]-1]+=1
  b[B[i]-1]+=1
a_count=0
b_count=0
flag=True
for i in range(m):
  a_count+=a[i]
  b_count+=b[i]
  if a[i]<b[i] and a_count<b_count:
    print('No')
    flag=False
if flag:
  print('Yes')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

n = int(input())
a_ = list(map(int, input().split()))
b_ = list(map(int, input().split()))

cmb = [(b_[i],a_[i]) for i in range(n)]
cmb.sort()

a = [cmb[i][1] for i in range(n)]
b = [cmb[i][0] for i in range(n)]

i = n-1
j = n-1
while i>0:
    if a[i]<=b[i]:
        i-=1
    else:
        while b[j]<a[i]:
            j-=1
            if j<0:
                print("No")
                sys.exit()
        i-=1
print("Yes")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = list(zip(a, b))
l.sort(key=lambda x: x[1])
a.sort()
s = list(set(a))
d = dict()
for i, x in enumerate(s):
    d[x] = i
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print('No')
        exit(0)
for i in range(n - 1):
    if a[i + 1] <= b[i]:
        print('Yes')
        exit(1)
al = [d[x[0]] for x in l]
cnt = 0
t = al[0]
while t != 0:
    t = al[t]
    cnt += 1
if cnt == n - 1:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
n, a, b = input().split("\n")
n = int(n)
a = list(map(int, a.split()))
b = list(map(int, b.split()))
a1 = sorted(a)
b1 = sorted(b)
c = zip(a1, b1)

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

Submission status: Runtime Error

Solution code:
import os

N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
m=max(max(A),max(B))
a=[0]*m
b=[0]*m
for i in range(N):
  a[A[i]-1]+=1
  b[B[i]-1]+=1
a_count=0
b_count=0
flag=True
for i in range(N):
  a_count+=a[i]
  b_count+=b[i]
  if a[i]<b[i] and a_count<b_count:
    print('No')
    flag=False
if flag:
  print('Yes')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, a, b = input().split("\n")
n = int(n)
a = list(map(int, a.split()))
b = list(map(int, b.split()))
a1 = sorted(a)
b1 = sorted(b)
c = zip(a1, b1)

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

Submission status: Runtime Error

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

for i in range(n):
    if max(a) < max(b):
        a.remove(max(a))
        b.remove(max(b))
    else:
        print('No')
        break
if len(a) == 0:
    print('Yes'）

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
c = zip(a1, b1)

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

Submission status: Runtime Error

Solution code:
def main():
	_ = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))

    k = sum([a>b for a, b in zip(sorted(A), sorted(B))])
    if k == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
b = map(int, input().split())
a1 = sorted(a)
b1 = sorted(b)
c = zip(a1, b1)

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = (int(x) for x in input().split())
B = (int(x) for x in input().split())

A.sort()
B.sort()

for x in range(N):
    if A[x] > B[x]:
        print("No")
        break
    
    if x == (N - 1):
        print("Yes")

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a_L = list(map(int,input().split()))
b_L = list(map(int,input().split()))

a_L = sorted(a_L)
b_L = sorted(b_L)

a = np.array(a_L)
b = np.array(b_L)

check = a-b
check = check <= 0

#print(check)

if False not in check:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

A'=[]
B'=[]
count=0

for i in range(N):
    A'.append(min(A))
    B'.append(min(B))
    if  A'[i]<=B'[i]:
        count+=1
    else:
        pass
if count==N:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
b.sort()
for i,j in zip(a,b):
    if i>j:
        print("No")
        exit()
RE

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a_L = list(map(int,input().split()))
b_L = list(map(int,input().split()))

a_L = sorted(a_L)
b_L = sorted(b_L)

a = np.array(a_L)
b = np.array(b_L)

if a-b <= 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input()))
B = list(map(int,input()))
A.sort()
B.sort()
ans = 'Yes'
for i in range(N):
    if A[i] > B[i]:
        ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    with open("input.txt", "r") as f:
        _ = int(f.readline())
        A = list(map(int, f.readline().split()))
        B = list(map(int, f.readline().split()))
    
    flag = False
    for a, b in zip(A, B):
        if a<=b:
            flag = True
            break

    if flag:
        k = sum([a>b for a, b in zip(sorted(A), sorted(B))])
        if k == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted(a)
d = sorted(b)
cnt = True
for i in range(n):
  if c[i]>d[i]:
    cnt = False
print("No" if c=c[::-1] else "Yes")