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:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
BA_list = [[B_list[i], A_list[i]] for i in range(N)]
BA_list.sort()
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        Flag1 = False
        ans = "No"
        break
    else:
        Flag1 = True
if Flag1:
    count = 0
    for i in range(N):
        if BA_list[i][1] == A_sort_list[i]:
            count += 1
            break
    if count > 0:
        ans = "Yes"
    else:
        Flag2 = False
        for i in range(N-1):
            if A_sort_list[i+1] <= B_sort_list[i]:
                Flag2 = True
        if Flag2:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    if a[i] <= b[i]:
        count += 1
if count == 0:
    flag = False
else:
    a.sort()
    b.sort()
    flag = True
    for i in range(n):
        if a[i] > b[i]:
            flag = False
            break
if flag == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

def wantp(n):

    nq = []
    while n != p[n]:
        nq.append(n)
        n = p[n]

    for i in nq:
        p[i] = n

    return n


N = int(input())

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

A2 = []
B2 = []

for i in range(N):

    A2.append([A[i],i])
    B2.append([B[i],i])

A2.sort()
B2.sort()

p = [i for i in range(N)]
rank = [1] * N

for i in range(N):

    if A2[i][0] > B2[i][0]:
        print ("No")
        sys.exit()

for i in range(N):

    na = A2[i][1]
    nb = B2[i][1]

    ap = wantp(na)
    bp = wantp(nb)

    if ap != bp:

        if rank[ap] > rank[bp]:
            p[bp] = ap

        elif rank[bp] > rank[ap]:
            p[ap] = bp

        else:
            p[ap] = bp
            rank[bp] += 1

nloop = 0

for i in range(N):

    if p[i] == i:
        nloop += 1

if nloop != 1:
    print ("Yes")
    sys.exit()


for i in range(N-1):

    if B[i] >= A[i+1]:
        print ("Yes")
        sys.exit()

print ("No")

Submission status: Wrong Answer

Solution code:
def main():

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

    B.sort()
    A.sort()

    for i in range(N):
        if A[i] > B[i]: return "No"

    if all(B[i+1] <= A[i] for i in range(N-1)): return "No"
    return "Yes"

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

Submission status: Wrong Answer

Solution code:
def main():

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

    B.sort()
    A.sort()

    for i in range(N):
        if A[i] > B[i]: return "No"

    if all(B[i+1] < A[i] for i in range(N-1)): return "No"
    return "Yes"

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

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

na = [a[i] for bi,i in pb]


ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    #sa => na が巡回置換か？
    d = {ai:i for i,ai in enumerate(sa)}
    ra = [d[ai] for ai in na]
    
    #print(ra,ok)    
    now = 0
    for i in range(n):
        now = ra[now]
        #print(now)
        if now == 0:
            break
    else: ok = 0    


    

#print(a,b,sa,sb,na)

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

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

na = [a[i] for bi,i in pb]


ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    #sa => na が巡回置換か？
    d = {ai:i for i,ai in enumerate(sa)}
    ra = [d[ai] for ai in na]
    
    print(ra)    
    now = 0
    for i in range(n-1):
        now = ra[now]
        #print(now)
        if now == 0:
            break
    else: ok = 0    

    
    
    

    

#print(a,b,sa,sb,na)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        Flag1 = False
        ans = "No"
        break
    else:
        Flag1 = True
if Flag1:
    count = 0
    for i in range(N):
        if A_list[i] <= B_list[i]:
            count += 1
    if count > 0:
        ans = "Yes"
    else:
        Flag2 = False
        for i in range(N-1):
            if A_sort_list[i+1] <= B_sort_list[i]:
                Flag2 = True
        if Flag2:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append([a[i],i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = ss(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

"""
ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][2] <= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    break
        else:
            ppppp = 0
            count += 1

"""

if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i][0] <= bb[i][0]:
            print("No")
            exit()
    for i in range(n-1):
        if aaa[i+1][0] <= b[aaa[i][1]]:
            print("Yes")
            break
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
input()
a = sorted([int(e) for e in input().split(" ")])
b = sorted([int(e) for e in input().split(" ")])
for x in zip(a, b):
  if x[1] < x[0]:
    print("No")
    break
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        Flag1 = False
        ans = "No"
    else:
        Flag1 = True
if Flag1:
    count = 0
    for i in range(N):
        if A_list[i] <= B_list[i]:
            count += 1
    if count > 0:
        ans = "Yes"
    else:
        Flag2 = False
        for i in range(N-1):
            if A_sort_list[i+1] <= B_sort_list[i]:
                Flag2 = True
        if Flag2:
            ans = "Yes"
        else:
            ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
def main():

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

    # B.sort()
    # A.sort()

    for i in range(N):
        if A[i] > B[i]: return "No"

    if all(B[i] < A[(i+1)%N] for i in range(N)): return "No"
    return "Yes"

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

Submission status: Wrong Answer

Solution code:
def main():

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

    B.sort()
    A.sort()

    for i in range(N):
        if A[i] > B[i]: return "No"

    if all(B[i] < A[(i+1)%N] for i in range(N)): return "No"
    return "Yes"

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

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [[a[i], b[i]] for i in range(n)]
a.sort(key=itemgetter(0))
b.sort()
c = 0
for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()
    if i > 0 and a[i][0] <= b[i-1]:
        c += 1
    if a[i][1] == b[i]:
        c += 1
if c > 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        Flag1 = False
    else:
        Flag1 = True
Flag2 = False
for i in range(N-1):
    if A_sort_list[i+1] <= B_sort_list[i]:
        Flag2 = True
Flag = Flag1 * Flag2
if A_sort_list == B_sort_list:
    Flag = True
if Flag:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][2] <= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    count += 1
                    break


if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = [[a[i], b[i]] for i in range(n)]
a.sort(key=itemgetter(0))
b.sort()
j = True
c = 0
for i in range(n):
    if a[i][0] > b[i]:
        print('No')
        sys.exit()
    if i > 0 and a[i-1][0] <= b[i]:
        c += 1
    if a[i][1] == b[i]:
        c += 1
if c > 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][2] <= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    ppppp = 0
                    break
        else:
            ppppp = 0
            count += 1


if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        ppppp = 0
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][2] <= bb[i][0]:
                ppppp += 1
                if ppppp >= 2:
                    break
        else:
            count += 1


if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline
import copy

#ライブラリインポート
from collections import defaultdict

class UnionFind:
	def __init__(self, n):
		self.par = [i for i in range(n + 1)]
		self.rank = [0] * (n + 1)
		self.size = [1] * (n + 1)

	def find(self, x):
		if self.par[x] == x:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def same_check(self, x, y):
		return self.find(x) == self.find(y)

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if self.rank[x] < self.rank[y]:
			if self.same_check(x, y) != True:
				self.size[y] += self.size[x]
				self.size[x] = 0
			self.par[x] = y
		else:
			if self.same_check(x, y) != True:
				self.size[x] += self.size[y]
				self.size[y] = 0
			self.par[y] = x
			if self.rank[x] == self.rank[y]:
				self.rank[x] += 1

	def siz(self, x):
		x = self.find(x)
		return self.size[x]

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	AA = copy.deepcopy(A)
	BB = copy.deepcopy(B)
	AA = sorted(AA)
	BB = sorted(BB)
	judge = "Yes"
	for i in range(N):
		if AA[i] > BB[i]:
			judge = "No"
			break

	if judge == "No":
		print("No")
	else:
		UF = UnionFind(N)
		C = [[B[i], A[i]] for i in range(N)]
		C = sorted(C)
		CC = [[C[i][1], i] for i in range(N)]
		CC = sorted(CC)
		for i in range(N):
			UF.union(i, CC[i][1])
		
		for i in range(N):
			UF.par[i] = UF.find(i)
		if UF.size[UF.find(0)] == N:
			print("No")
		else:
			print("Yes")

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
ans = "Yes"
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        ans = "No"
if ans == "Yes":
    ans = "No"
    for i in range(N-1):
        if A_sort_list[i+1] <= B_sort_list[i]:
            ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
ans = "Yes"
A_sort_list = sorted(A_list)
B_sort_list = sorted(B_list)
for i in range(N):
    if A_sort_list[i] > B_sort_list[i]:
        ans = "No"
if ans == "Yes":
    ans = "No"
    for i in range(N-1):
        if A_sort_list[i+1] > B_sort_list[i]:
            ans = "Yes"
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


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)
for i in range(n-1):
    if s[i+1] > t[i]:
        st.add(i, 1)
print(s)
print(t)
s = sorted(zip(a, range(len(a))))
for i in range(n):
    # 固定して考える
    if s[i][0] <= b[s[i][1]]:
        ind_s = i
        ind_t = bisect.bisect_right(t, b[s[i][1]])
        if st.get_sum(ind_s, ind_t-1) == 0:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
# 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 any(a > b for a, b in zip(sort_A, sort_B)) or (all(a != b for a, b in zip(A, sort_A)) and all(a > b for a, b in zip(sort_A[1:], sort_B))):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
# 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 any(a > b for a, b in zip(sort_A, sort_B)) or all(a != b for a, b in zip(A, sort_A)) or all(a > b for a, b in zip(sort_A[1:], sort_B)):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def ss(x): #圧縮
    a = []
    aa = x[0][0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1][0]:
            a.append([aa,su])
            aa = x[i+1][0]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
b = l()

aaa = []
bb = []
co = 0
for i in range(n):
    if a[i] <= b[i]:
        co += 1
    aaa.append(a[i])
    bb.append([b[i],i,a[i]])

aaa.sort()
bb.sort()
ppp = sorted(bb,key = lambda x:x[2])
aa = s(aaa)
bbb = ss(bb)
kkk = {}
bkb = {}
count = 0
for i in range(len(aa)):
    kkk[aa[i][0]] = [count,count + aa[i][1] - 1]
    count += aa[i][1]

count = 0
for i in range(len(bbb)):
    bkb[bbb[i][0]] = [count,count + bbb[i][1] - 1]
    count += bbb[i][1]

count = 0

ppppp = 0
for i in range(n):
    k = bb[i][2]
    if bkb[bb[i][0]][1] >= kkk[k][0] and kkk[k][1] >= bkb[bb[i][0]][0]:
        count += 0
    else:
        ppppp = 0
        for j in range(kkk[k][1]-kkk[k][0]+1):
            if ppp[j+kkk[k][0]][0] >= bb[i][2]:
                ppppp += 1
                if ppppp >= 2:
                    break
        else:
            count += 1


if count > n-1:
    print("No")
else:
    for i in range(n):
        if not aaa[i] <= bb[i][0]:
            print("No")
            exit()
    print("Yes")

Submission status: Wrong Answer

Solution code:

import sys

N = int(input())

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

B = list(map(int,input().split()))
"""
A2 = []
B2 = []

for i in range(N):
    A2.append([A[i],i])
for j in range(N):
    B2.append([B[i],i])

A2.sort()
B2.sort()

"""

able = 0
nable = 0


for i in range(N):

    if A[i] <= B[i]:
        able += 1
    else:
        nable += 1





if nable == N:
    print ("No")
    sys.exit()

A.sort()
B.sort()


for i in range(N):

    if A[i] > B[i]:
        print ("No")
        sys.exit()

print ("Yes")

Submission status: Wrong Answer

Solution code:
# 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 any(a > b for a, b in zip(sort_A, sort_B)) or all(a > b for a, b in zip(sort_A[1:], sort_B)):
    print("No")
else:
    print("Yes")

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"

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

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



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


        if b[index1] <= c[index2]:
            b[index1], b[index2] = b[index2], b[index1]

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

print(out)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
n = int(input())
#a = list(map(int,input().split()))
#b = list(map(int,input().split()))
a = [int(s) for s in sys.stdin.readline().split()]
b = [int(t) for t in sys.stdin.readline().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 np.all(sorta <= sortb):
    ans = 'Yes'
else:
    ans = 'No'

if ans=='Yes' and 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 sorta[i+1]<= sortb[i]:
            ans = 'Yes'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect


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)
for i in range(n-1):
    if s[i+1] > t[i]:
        st.add(i, 1)

s = sorted(zip(a, range(len(a))))
for i in range(n):
    # 固定して考える
    if s[i][0] <= b[s[i][1]]:
        ind_s = i
        ind_t = bisect.bisect_left(t, b[s[i][1]])
        if st.get_sum(ind_s, ind_t) == 0:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
# 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 any(a > b for a, b in zip(sort_A, sort_B)):
    print("No")
    exit()

if all(a != a_s for a, a_s in zip(A, sort_A))and all(a > b for a, b in zip(sort_A[1:], sort_B)):
    print("No")
else:
    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()))
  tmp={}
  for i in range(N):
    if not B[i] in tmp.keys():
      tmp[B[i]]=[]
    tmp[B[i]].append(A[i])
  A.sort()
  B.sort()
  for i in range(N):
    if A[i]>B[i]:
      print("No")
      return 0
  for i in range(N):
    if A[i] in tmp[B[i]]:
      print("Yes")
      return 0
    if i!=N-1:
      if B[i] >= A[i+1]:
        print("Yes")
        return 0
  print("No")
      
main()