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:
#!/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()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * n
    for i in range(n):
        if ca[i] > cb[i]:
            print("Yes")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                # print("Yes", d, first, end, f, i)
                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:
#!/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()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * n
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                print("")
                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:
print("YES")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ba = sorted((y, x) for x, y in zip(a, b))
a = [x for y, x in ba]
b = [y for y, x in ba]

ap = sorted((x, i) for i, x in enumerate(a))
for i in range(n):
    if ap[i][0] > b[i]:
        print('No')
        exit()

rep = [ap[i][1] for i in range(n)]
used = [False] * n
c = 0
for i in range(n):
    if used[i]:
        break
    used[i] = True
    p = rep[i]
    c += 1
    while True:
        if used[p]:
            break
        used[p] = True
        p = rep[p]
if c > 1:
    print('Yes')
    exit()

for i in range(n - 1):
    if ap[i + 1][0] <= b[i]:
        print('Yes')
        exit()

print('No')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
c = sorted(a)
d = sorted(b)
for i in range(n):
    if c[i] > d[i]:
        print('No')
        quit()
for i in range(n-1):
    if c[i] < d[i+1]:
        print('Yes')
        break
else:
    print('No')

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()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * n
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))

    for i in range(n):
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                print("No")
                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:
#!/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()
    res = None
    for i in range(n):
        if a[i] <= b[i]:
            res = True
    if res == None:
        print("No")
        return
    ca = a[::1]
    cb = b[::1]
    ca.sort()
    cb.sort()
    d = [0] * n
    for i in range(n):
        if ca[i] > cb[i]:
            print("No")
            return
        if i == 0:
            continue
        d[i] = ca[i] <= cb[i - 1]
    d = list(itertools.accumulate(d))
    for i in range(n):
        f = True
        if a[i] <= b[i]:
            first = bisect_left(ca, a[i])
            end = bisect_right(cb, b[i]) - 1
            f = d[end] - d[first]
            if f == end - first:
                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:
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 A[i] in tmp.keys():
      tmp[A[i]]=[]
    tmp[A[i]].append(B[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 B[i] in tmp[A[i]]:
      print("Yes")
      return 0
  for i in range(N-1):
    if B[i]>=A[i+1]:
      print("Yes")
      return 0
  print("No")
      
main()

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy

n = int(input())
a_org  = [num for num in input().split(' ')]
b_org  = [num for num in input().split(' ')]

# print(n, a_org, b_org)

a_sorted_i = sorted(range(n), key=lambda i:a_org[i])
b_sorted_i = sorted(range(n), key=lambda i:b_org[i])

# print(a_sorted_i, b_sorted_i)

# ①AとBをソートして、すべての要素の大小関係(ai <= bi) が成り立っていること
#　成り立っていなければNo
for i in range(n):
  index_a = a_sorted_i[i]
  index_b = b_sorted_i[i]
  a = a_org[index_a]
  b = b_org[index_b]
  if a > b:
    print('No')
    sys.exit()

# ②Aについてソートされたところを辿ってグラフを作る
# 　サイクルが２個以上になったらYes

def get_cycle(i_list, start_index):
  cycle = []
  current_index = start_index
  while True:
    cycle.append(current_index)
    next_index = i_list.index(current_index)
    if next_index == start_index:
      break
    current_index = next_index
  return cycle

def next_index(i_list):
  i_list.sort()
  for i in range(len(i_list)):
    if i != i_list[i]:
      return i
  return len(i_list)

def get_cycles(i_list):
  cycles = []
  start_index = 0
  target_list = deepcopy(i_list)
  used_index_list = []
  while True:
    cycle = get_cycle(target_list, start_index)
    cycles.append(cycle)
    
    if len(cycles) > 1:
      print('Yes')
      sys.exit()
    used_index_list.extend(cycle)
    start_index = next_index(used_index_list)
    # print('next start_index: {}'.format(start_index))
    # print('used_index_list: {}'.format(used_index_list))
    
    if start_index >= len(i_list):
      break
    
  
  return cycles

cycles = get_cycles(a_sorted_i)
# サイクルグラフの作成中に、2つ以上になる際は Yes で終了させる
# if len(cycles) > 1:
#   print('Yes')
#   sys.exit()

# ③B[n] < A[n+1] が成り立っているか検証
# A1　A2　A3　。。。　AN
# 　　B1　B2　B3　。。。　BN
# 一箇所でも成り立たなければyes

for i in len(n-1):
  index_a = a_sorted_i[i+1]
  index_b = b_sorted_i[i]
  a = a_org[index_a]
  b = b_org[index_b]
  if b < a:
    print('Yes')
    sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy

n = int(input())
a_org  = [num for num in input().split(' ')]
b_org  = [num for num in input().split(' ')]

# print(n, a_org, b_org)

a_sorted_i = sorted(range(n), key=lambda i:a_org[i])
b_sorted_i = sorted(range(n), key=lambda i:b_org[i])

# print(a_sorted_i, b_sorted_i)

# ①AとBをソートして、すべての要素の大小関係(ai <= bi) が成り立っていること
#　成り立っていなければNo
for i in range(n):
  index_a = a_sorted_i[i]
  index_b = b_sorted_i[i]
  a = a_org[index_a]
  b = b_org[index_b]
  if a > b:
    print('No')
    sys.exit()

# ②Aについてソートされたところを辿ってグラフを作る
# 　サイクルが２個以上になったらYes

def get_cycle(i_list, start_index):
  cycle = []
  current_index = start_index
  while True:
    cycle.append(current_index)
    next_index = i_list.index(current_index)
    if next_index == start_index:
      break
    current_index = next_index
  return cycle

def next_index(i_list):
  i_list.sort()
  for i in range(len(i_list)):
    if i != i_list[i]:
      return i
  return len(i_list)

def get_cycles(i_list):
  cycles = []
  start_index = 0
  target_list = deepcopy(i_list)
  used_index_list = []
  while True:
    cycle = get_cycle(target_list, start_index)
    cycles.append(cycle)
    used_index_list.extend(cycle)
    start_index = next_index(used_index_list)
    # print('next start_index: {}'.format(start_index))
    # print('used_index_list: {}'.format(used_index_list))
    
    if start_index >= len(i_list):
      break
    
  
  return cycles

cycles = get_cycles(a_sorted_i)
if len(cycles) > 1:
  print('Yes')
  sys.exit()

# ③B[n] < A[n+1] が成り立っているか検証
# A1　A2　A3　。。。　AN
# 　　B1　B2　B3　。。。　BN
# 一箇所でも成り立たなければyes

for i in len(n-1):
  index_a = a_sorted_i[i+1]
  index_b = b_sorted_i[i]
  a = a_org[index_a]
  b = b_org[index_b]
  if b < a:
    print('Yes')
    sys.exit()

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 = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print(a_sort[1:])
    print(b_sort[:-1])
    print('Yes')
    exit()

# 2-b （startをとりあえず0番目とかにする）
index = b.argsort()
a = a[index]
sort_dict = a.argsort().tolist()
from_ = 0
count = 0
while True:
    count += 1
    from_ = sort_dict[from_]
    if from_ == 0:
        break

if count != n:
    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 = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print('Yes')
    exit()

# 2-b （startをとりあえず0番目とかにする）
a_ = a.argsort().tolist()
from_ = 0
count = 0
while True:
    count += 1
    from_ = a_[from_]
    if from_ == 0:
        break

if count != n:
    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 = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print('Yes')
    exit()

# 2-b （startをとりあえず0番目とかにする）
a_ = (a.argsort() ).tolist()
print(a_)
from_ = 0
count = 0
while True:
    count += 1
    from_ = a_[from_]
    if from_ == 0:
        break

if count != n:
    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 = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
if (a_sort[1:] <= b_sort[:-1]).any():
    print('Yes')
    exit()

# 2-b （startをとりあえず0番目とかにする）
a_ = (a.argsort() ).tolist()
print(a_)
from_ = 0
count = 0
while True:
    count += 1
    from_ = a_[from_]
    if from_ == 0:
        break

if count == n:
    print('No')
else:
    print('Yes')

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 = np.sort(a)
b_sort = np.sort(b)

# 1. 回数関係なくそもそも不可能なやつ → no
# 2-a. サイクルは1つだとしても，完璧じゃない組み合わせが1つ以上許容されるやつ → yes
# 2-b. サイクルが2以上にわけられるやつ → yes

# 1
if (a_sort > b_sort).any():
    print('No')
    exit()

# 2-a
# if (a_sort[1:] <= b_sort[:-1]).any():
#     print('Yes')
#     exit()

# 2-b （startをとりあえず0番目とかにする）
a_ = (a.argsort() ).tolist()
print(a_)
from_ = 0
count = 0
while True:
    count += 1
    from_ = a_[from_]
    if from_ == 0:
        break

if count == n:
    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()))
import numpy as np
a = sorted(A)
b = sorted(B)
a = np.array(a)
b = np.array(b)
A = np.array(A)
B = np.array(B)
if (a<=b).sum()!=N:
  print('No')

else:
  bx = np.argsort(B)
  A = A[bx]
  ax = np.argsort(A)
  dic = {}
  for i,x in enumerate(ax):
    dic[x]=i
    
  m = 0
  c = 0
  while True:
    m = dic[m]
    c += 1
    
    if (c==N) and (m==0):
      break
    else:
      print('Yes')
      exit()
      
  judge = False
  for i in range(N-1):
    if b[i]>=a[i+1]:
      judge = True
      break
      
  if judge:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split(' ')])
b = sorted([int(x) for x in input().split(' ')])

flg = ''


for i in range(n) :
    if(a[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

# if (flg == 'Yes') :
#     for i in range(n-1) :
#         if(a[i] <= b[i+1]) :
#             flg = 'Yes'
#             break
#     else:
#         flg = 'No'


print(flg)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split(' ')])
b = sorted([int(x) for x in input().split(' ')])

flg = ''


for i in range(n) :
    if(a[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

if (flg == 'Yes') :
    for i in range(n-1) :
        if(a[i] <= b[i+1]) :
            flg = 'Yes'
            break
    else:
        flg = 'No'


print(flg)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split(' ')])
b = sorted([int(x) for x in input().split(' ')])

flg = ''


for i in range(n) :
    if(a[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

if (flg == 'Yes') :
    for i in range(n-1) :
        if(a[i] > b[i+1]) :
            flg = 'No'
            break
    else:
        flg = 'Yes'


print(flg)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(x) for x in input().split(' ')])
b = sorted([int(x) for x in input().split(' ')])

flg = ''


for i in range(n) :
    if(a[i] > b[i]) :
        flg = 'No'
        break
else:
    flg = 'Yes'

for i in range(n-1) :
    if(a[i] > b[i+1]) :
        flg = 'No'
        break
else:
    flg = 'Yes'


print(flg)