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
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def init(n):
  for i in range(N+1):
    par[i] = i
    rnk[i] = 0
def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
def unite(x, y):
  x = find(x)
  y = find(y)
  if x == y:
    return
  if (rnk[x] < rnk[y]):
    par[x] = y
  else:
    par[y] = x
    if(rnk[x] == rnk[y]):
      rnk[x] += 1
def same(x, y):
  return find(x) == find(y)

N = I()
a = IL()
b = IL()

par = [0 for i in range(N+1)]
rnk = [0 for i in range(N+1)]
init(N)

adata = []
bdata = []
for i in range(N):
  adata.append([a[i], i])
  bdata.append([b[i], i])
adata.sort()
bdata.sort()
print(adata)
print(bdata)

for i in range(N-1):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  atmp2, aID2 = adata[i + 1]
  btmp2, bID2 = bdata[i + 1]
  if atmp > btmp or atmp2 > btmp2:
    print("No")
    exit()
  if atmp2 <= btmp:
    print("Yes")
    exit()

for i in range(N-1):
  atmp, aID = adata[i]
  btmp, bID = bdata[i]
  #print("---")
  #print(atmp,aID)
  #print(btmp,bID)
  if aID == bID:
    break
  if same(aID, bID):
    break
  else:
    unite(aID, bID)
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()))

count = 0
y = 0

A_B = []

for n in range(N):
    A_B.append([A[n],B[n]])

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

for n in range(N-1):
    if A_B[n][0] > A_B[n][1]:
        y += 1
        break
    elif A_B[n+1][0] > A_B[n][1]:
        count += 1

if y >= 1:
    print('No')
elif count == N-1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
A = III()
B = III()

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

print('No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
import heapq

INF = 10 ** 9 + 2

def sort_likeB(A, B_idx):
    N = len(A)
    new_A = [0] * N
    for i in range(N):
        new_A[i] = A[B_idx[i]]
    return new_A


def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    B = [(int(v), i) for i, v in enumerate(input().split())]
    B = sorted(B)
    B_idx = [i for (v, i) in B]
    B = [v for (v, i) in B]
    A = sort_likeB(A, B_idx)

    num = INF
    for i in range(N):
        if B[i] >= A[i]:
            num = i
            break
    if num == INF:
        print("No")
        sys.exit()

    heap = []
    for i in range(N):
        if i == num:
            continue
        heapq.heappush(heap, A[i])
    
    for i in range(N):
        if i == num:
            continue
        else:
            if B[i] < heapq.heappop(heap):
                print("No")
                sys.exit()
            else:
                continue
    print("Yes")    


if __name__ == '__main__':
    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):
        f = True
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i])
            for i in range(first + 1, end):
                if ca[i] <= cb[i]:
                    continue
                f = False
            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())
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


def checkCirculation(list1, list2):
    nList2 = sorted(list2)
    sortedIndex = []
    for e in nList2:
        sortedIndex.append(list2.index(e))

    nList1 = []
    minindex = 0
    kensa = 1000000000
    for i in sortedIndex:
        nList1.append(list1[i])
        if (list2[i] < kensa):
            kensa = list2[i]
            minindex = i

    kensa2 = 0
    for n in range(minindex, N):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False

    kensa2 = 0
    for n in range(0, minindex - 1):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False

    return True


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

if (maxA > maxB or minA > minB or sumA > sumB or checkCirculation(listA, listB)):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
def check(listA, listB):
    for i in range(len(listA)):
       if listA[i] > listB[i]:
           return False
    return True
    
def solution3(N, listA, listB):
    cnt = 0
    max_A = max(listA)
    max_B = max(listB)
    if max_A > max_B:
        return False
    if check(listA, listB):
    	return True   
    loopIndex = [int(i) for i in range(len(listA))]
    for i in range(len(listA)-2):
        max_A = 0
        max_B = 0
        for j in loopIndex:
            if max_A < listA[j]:
                max_index_A = j
                max_A = listA[j]
            if max_B < listB[j]:
                max_index_B = j
                max_B = listB[j]

        # swap
        temp = listA[max_index_B]
        listA[max_index_B] = max_A
        listA[max_index_A] = temp
        loopIndex.remove(max_index_B)

    if check(listA, listB):
        return True
    
    return False
  
N = int(input())
listA = input()
listA = [int(n) for n in listA.split(" ")]
listB = input()
listB = [int(n) for n in listB.split(" ")]

if solution3(N, listA, listB):
    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()))
ASort=sorted(A)
BSort=sorted(B)
g=0
for i in range(N):
    if ASort[i]>BSort[i]:
        g=1
        break
ans0=0
ans1=0
for i in range(N):
    if A[i]>B[i]:
        ans0+=1
    else:
        ans1+=1
if ans1>0:
    if  ans0>ans1:
        ans=ans1+(ans0-ans1)//2+(ans0-ans1)%2
    else:
        ans=ans0
else:
    ans=ans0//2+ans0%2
if ans>N-2 or g==1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

As = sorted(A)
Bs = sorted(B)

flag = False
comp = True
for i in range(N):
    if As[i] == A[i]:
        flag = True
    if As[i] > Bs[i]:
        comp = False
if flag and comp:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a = int(input())
b = input().split()
c = input().split()

for i in range(a):
    b[i] = int(b[i])
    c[i] = int(c[i])

out = "Yes"

b_sort = sorted(b)
c_sort = sorted(c)

print(b, c)
print(b_sort, c_sort)

for i in range(a):
    if b_sort[i] > c_sort[i]:
        print(i, b_sort[i], c_sort[i])
        out = "No"
        break


max_b = 0
max_bi = -1
fin_list = []

def check_max(l, num):
    max_num = 0
    max_i = -1

    l_sorted = sorted(l)
    num_list = [-1] * num
    num_list2 = [-1] * num

    for i in reversed(range(num)):
        for j in range(num):
            if l_sorted[i] == l[j]:
                if num_list[j] == -1:
                    num_list[j] = i+1
                    num_list2[i] = j
                    break

    return (num_list, list(reversed(num_list2)))

def checklist(l1, l2, num):
    result = True
    for i in range(num):
        if l1[i] > l2[i]:
            result = False
            break
    return result 


if out == "Yes":
    swap_num = 0
    print(check_max(b,a))
    print(check_max(c,a))

    print(checklist(b, c, a))

    # if b[tmpbi] > c[tmpbi]:
    #     b[tmpbi], b[tmpci] = b[tmpci], b[tmpbi]
    #     swap_num += 1

    # print(checklist(b, c, a))

    num_list_b, num_list_b_index = check_max(b,a)
    num_list_c, num_list_c_index = check_max(c,a)

    print(num_list_b_index)
    print("b", b, num_list_b_index)

    for i in range(a-2):
        index1 = num_list_b_index[i]
        index2 = num_list_c_index[i]

        if not checklist(b, c, a):
            b[index1], b[index2] = b[index2], b[index1]

            print("b", b, num_list_b_index)
        else:
            break

    # b[tmpbi], b[tmpci] = b[tmpci], b[tmpbi]


print(b)
print(c)

if not checklist(b, c, a):
    out = "No"
else:
    out = "Yes"

print(out)

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()
        
s = 0
count = 0
if a[1] > b[0]:
    while A[0] < a[0]:
        s = A[0]
        A[0] = A[s]
        count +=1
    if count > N - 2:
        print("No")

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()))
A=sorted(a,reverse=True)
B=sorted(b,reverse=True)
cnt=0
if n==2:
  if a[0]<=b[0] and a[1]<=b[1]:
    print('Yes')
    sys.exit()
  else:
    print('No')
    sys.exit()
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:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
import sys
import heapq
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]
a_min=[]
b_min=[]
 
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):
	print("No")
	sys.exit()
a_min=heapq.nsmallest(2, a)
b_min=heapq.nsmallest(2, b)
if a.index(a_min[0])>a.index(a_min[1]):
        a_min[0],a_min[1]=a_min[1],a_min[0]
if b.index(b_min[0])>b.index(b_min[1]):
        b_min[0],b_min[1]=b_min[1],b_min[0]
 
detection(a_min,b_min)

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_raw_a = np.array(A)
    array_raw_b = np.array(B)
    need_to_exchange = (array_raw_b - array_raw_a) < 0

    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'
    elif sum(need_to_exchange) > N - 2:
        result = 'No'
    elif sum(need_to_exchange) == N - 2:
        not_need_to_exchange = np.where(~need_to_exchange)
        for idx in not_need_to_exchange:
            deleted_a = np.sort(np.delete(array_raw_a, idx))
            deleted_b = np.sort(np.delete(array_raw_b, idx))
            if sum((deleted_b - deleted_a) < 0) > 0:
                result = 'No'

    print(result)


if __name__ == '__main__':
    answer()

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

Submission status: Wrong Answer

Solution code:
class SegmentTree():
    """一点加算、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    add: i番目にvalを加える
    get_sum: 区間[begin, end)の和を求める
    """
    def __init__(self, n):
        self.n = n
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [0] * (2*self.size - 1)

    def add(self, i, val):
        i += (self.size - 1)
        self.node[i] += val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = self.node[2*i + 1] + self.node[2*i + 2]

    def get_sum(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = 0
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s += self.node[end]
            if (begin - 1) & 1:
                s += self.node[begin]
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s

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

s = sorted(a)
t = sorted(b)
for i in range(n):
    if s[i] > t[i]:
        print("No")
        exit()
st = SegmentTree(n)

s = sorted(zip(a, range(len(a))))
t = sorted(zip(b, range(len(b))))
memo_s= {}
memo_t = {}
for i in range(n):
    memo_s[s[i][1]] = i
    memo_t[t[i][1]] = i

for i in range(n-1):
    if a[i+1] > b[i]:
        st.add(i, 1)

for i in range(n):
    if memo_s[i] <= memo_t[i]:
        if st.get_sum(memo_s[i], memo_t[i] + 1) == 0:
            print("Yes")
            exit()
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()))
A=sorted(a,reverse=True)
B=sorted(b,reverse=True)
cnt=0
if n==2:
  if a[0]<=b[0] and a[1]<=a[2]:
    print('Yes')
  else:
    print('No')
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:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right, bisect_left
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
sortedAs = sorted(As)
sortedBs = sorted(Bs)
arr = []
for i in range(N):
    if sortedAs[i] > sortedBs[i]:
        print('No')
        exit()
    if i >= 1 and sortedAs[i] > sortedBs[i-1]:
        arr.append(i)
for a, b in zip(As, Bs):
    idxa = bisect_right(sortedAs, a)
    idxb = bisect_left(sortedBs, b)
    if idxb <= idxa or bisect_right(arr, idxa) == bisect_left(arr, idxb):
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
import heapq
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]
a_min=[]
b_min=[]
 
def detection (a,b):
    for i in range(len(a)-1):
        if a[i]-b[i]>0:
            print("No")
            sys.exit()
    print("Yes")
 

a_min=heapq.nsmallest(2, a)
b_min=heapq.nsmallest(2, b)
if a.index(a_min[0])>a.index(a_min[1]):
        a_min[0],a_min[1]=a_min[1],a_min[0]
if b.index(b_min[0])>b.index(b_min[1]):
        b_min[0],b_min[1]=b_min[1],b_min[0]
 
detection(a_min,b_min)

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()]
A_s, B_s = sorted(A), sorted(B)
if any(a > b for a, b in zip(A_s, B_s)):
    print("No")
    quit()
perm = [0] * N
A_idx = [(a, i) for i, a in enumerate(A)]
A_idx.sort()
B = [B[idx] for _, idx in A_idx]
B_idx = [(b, i) for i, b in enumerate(B)]
B_idx.sort()
for i, (_, idx) in enumerate(B_idx):
    perm[idx] = i
cycle_len = 0
used = [False] * N
for i in range(N):
    if used[i]:
        continue
    cnt = 0
    now = i
    while not used[now]:
        used[now] = True
        cnt += 1
        now = perm[now]
    cycle_len += cnt - 1
if cycle_len == N - 1:
    print("No")
else:
    print("Yes")

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 = collections.defaultdict(set)
    for i in range(N):
        if A[i] in tmp[A_[i]]:
            print("Yes")
            exit(0)
        else:
            tmp[A[i]].add(A_[i])

    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) and (a-1>0 or getvalue(a-1)>=getvalue2(a-1)) and (b-1>0 or 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:
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")
    exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cir = False
ans = 'Yes'

sorta = np.sort(a)
sortb = np.sort(b)
indexa = np.argsort(a)
indexb = np.argsort(b)
index2b = np.concatenate([indexb,indexb])

#循環してるか
for i in range(n):
    if np.all(indexa == index2b[i:i+n]):
        cir = True
        break

if not cir:
    for i in range(n):
        if sorta[i] > sortb[i]:
            ans = 'No'
        break

if cir:
    ans = 'No'
    for i in range(1,n-1):
        temp = np.array(sorta.copy())
        temp[i], temp[i+1] = temp[i+1], temp[i]
        if np.all(temp <= sortb):
            ans = 'Yes'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

cnt_A = collections.Counter(A)
cnt_B = collections.Counter(B)

cnt_over = 0
for i in range(N+1, max(B)+1):
    cnt_over += cnt_B[i]

A.sort()
B.sort()

if len(A)-cnt_over > 0:
    A = A[:len(A)-cnt_over]
    B = B[:len(B)-cnt_over]

    if A[-1] <= B[-1]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

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


def checkCirculation(list1, list2):
    nList2 = sorted(list2)
    sortedIndex = []
    for e in nList2:
        sortedIndex.append(list2.index(e))

    nList1 = []
    minindex = 0
    kensa = 1000000000
    for i in sortedIndex:
        nList1.append(list1[i])
        if (list2[i] < kensa):
            minindex = i

    kensa2 = 0
    for n in range(minindex, N):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False

    kensa2 = 0
    for n in range(1, minindex - 1):
        if (kensa2 <= nList1[n]):
            kensa2 = nList1[n]
        else:
            return False

    return True


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

if (maxA > maxB or minA > minB or sumA > sumB or checkCirculation(listA, listB)):
    print('No')
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_sort[i] >= B_sort[i]:
            print("No")
            exit(0)
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import heapq
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
sub=[]
a_min=[]
b_min=[]
 
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:
    a_min=heapq.nsmallest(2, a)
    b_min=heapq.nsmallest(2, b)
    if a.index(a_min[0])>a.index(a_min[1]):
        a_min[0],a_min[1]=a_min[1],a_min[0]
    if b.index(b_min[0])>b.index(b_min[1]):
        b_min[0],b_min[1]=b_min[1],b_min[0]
 
detection(a_min,b_min)

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)

mm = max(aa)
mm2 = max(aa[:n-1])
if n >=3:
    mm3 = max(aa[:n-2])

for i in range(n):
    if aa[i] > bb[i]:
        print('No')
        exit()
    if i != n-1 and mm <= bb[i]:
        print('Yes')
        exit()
    if n >= 5 and i != n-1 and mm2 <= bb[i]:
        print('Yes')
        exit()
    if n>=5 and i !=n-1 and mm3 <= bb[i]:
        print('Yes')
        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()

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

q = [abd[0]]
chk = [0]*n
chk[0] = 1

while q:
    x = q.pop()
    if chk[x] == 0:
        chk[x] = 1
        q.append(abd[x])

if sum(chk) != n:
    print('Yes')
else:
    print('No')

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)
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:
import sys

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
        print("No")
        sys.exit()

if check:
    print("Yes")

Submission status: Wrong Answer

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

data = set()
sA = sorted(A)
sB = sorted(B)
count = 0
for i in range(N):
    sa, sb = sA[i], sB[i]
    if sa > sb:
        print('No')
        break
    data.add(str(sa)+":"+str(sb))
else:
    for i in range(N):
        if (str(A[i])+":"+str(B[i])) in data:
            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()))
d = [b[i]-a[i] for i in range(n)]
l = len(list(filter(lambda x:x<0,d)))
m = 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 > m:
  ans = 'No'

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
import heapq

INF = 10 ** 9 + 2

def sort_likeB(A, B_idx):
    N = len(A)
    new_A = [0] * N
    for i in range(N):
        new_A[i] = A[B_idx[i]]
    return new_A


def main():
    N = int(input())
    A = [int(c) for c in input().split()]
    B = [(int(v), int(i)) for i, v in enumerate(input().split())]
    B = sorted(B)
    B_idx = [i for (v, i) in B]
    B = [v for (v, i) in B]
    A = sort_likeB(A, B_idx)

    num = INF
    for i in range(N):
        if B[i] >= A[i]:
            num = i
            break
    if num == INF:
        print("No")
        sys.exit()
    
    heap = []
    for i in range(N):
        if i == num:
            continue
        heapq.heappush(heap, A[i])
    
    for i in range(N):
        if i == num:
            continue
        else:
            if B[i] < heapq.heappop(heap):
                print("No")
                sys.exit()
            else:
                continue
    print("Yes")    


if __name__ == '__main__':
    main()