Problem:


Score : 600 points

Problem Statement

We have one slime.

You can set the health of this slime to any integer value of your choice.

A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second.

Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S.

Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N}.

Constraints

All values in input are integers.

1 \leq N \leq 18

1 \leq S_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
S_1 S_2 ... S_{2^N}

Output

If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S, print Yes; otherwise, print No.

Sample Input 1

2
4 2 3 1

Sample Output 1

Yes

We will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S.

First, set the health of the first slime to 4.

By letting the first slime spawn a slime whose health is 3, the healths of the slimes that exist in 1 second can be 4,~3.

Then, by letting the first slime spawn a slime whose health is 2, and letting the second slime spawn a slime whose health is 1, the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1, which is equal to S as multisets.

Sample Input 2

2
1 2 3 1

Sample Output 2

Yes

S may contain multiple instances of the same integer.

Sample Input 3

1
1 1

Sample Output 3

No

Sample Input 4

5
4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3

Sample Output 4

No



Sample input:
2
4 2 3 1


Sample output:
Yes

Submission status: Time Limit Exceeded

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(10**6)
n=i1()
s=i2()
import heapq
import bisect
s.sort()
heapq.heapify(s)
x=[s[-1]]
s.pop(-1)
a="Yes"
for i in range(n):
 y=[]
 for j in range(1<<i):
   z=bisect.bisect_left(s,x[j])-1
   if z<0:
     a="No"
   y.append(s[z])
   s.pop(z)
 x+=y
 x.sort(reverse=True)
print(a)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
S = [int(i) for i in input().split()]

def solve() :
    S.sort()
    T = [S.pop()]
    for i in range(N) :
        T.sort(reverse=True)
        for j in range(2**i) :
            if S[0] >= T[j] :
                return 'No'
            
            pos = bisect_left(S, T[j])
            T.append(S.pop(pos-1))
            
    return 'Yes'
    
print(solve())

Submission status: Time Limit Exceeded

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys


def solve(N, S):
    S = sorted(S)
    used = [S[-1]]
    unused = S[:-1]
    num_of_generation = 1
    while len(used) < 2 ** N:
        next_used = []
        for i in range(num_of_generation):
            loc = bisect_left(unused, used[i])
            if loc == 0:
                return False
            else:
                next_used.append(used[i])
                next_used.append(unused[loc - 1])
                del unused[loc - 1]
        used = next_used
        num_of_generation *= 2
    return True


N = int(input())
S = list(map(int, input().split()))
print("Yes" if solve(N, S) else "No")

Submission status: Time Limit Exceeded

Solution code:
def insort_right(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it sorted assuming a is sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """

    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo + hi) // 2
        if x > a[mid]:
            hi = mid
        else:
            lo = mid + 1
    a.insert(lo, x)


n = int(input())
s = list(map(int, input().split()))
s.sort()
slimes = [s.pop()]
deque = []
flag = False
prol = False
for i in range(n):
    for j in slimes[::-1]:
        prol = False
        for k, hp in enumerate(deque):
            if hp < j:
                insort_right(slimes, deque.pop(k))
                prol = True
                break
        while not prol:
            if len(s) == 0:
                flag = True
                break
            indiv = s.pop(-1)
            if indiv < j:
                slimes.append(indiv)
                prol = True
            else:
                deque.append(indiv)
        if flag:
            break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
def f_f():
    n = int(input())
    *s, = map(int, input().split())
    s.sort()
    p1, p2 = [s[-1]], []
    s[-1] = -1
    o = "Yes"
    for _ in range(n):
        j = len(s)
        while j>-1 and p1:
            j -= 1
            if s[j]<0:
                pass
            elif p1[-1]>s[j]:
                p2 += [s[j], p1.pop()]
                s[j] = -1
                j = len(s)
        if p1:
            o="No"
            break
        p1, p2 = sorted(p2), []
    print(o)

if __name__ == "__main__":
    f_f()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]
cnt = Counter(a)

key_num = len(cnt.keys())
rank = [0] * key_num 
keys = list(cnt.keys())
keys.sort(reverse=True)
for i, key in enumerate(keys):
    rank[i] = cnt[key]
cur = [0] * key_num 
cur[0] = 1
for i in range(n):
    tmp = cur[:]
    for j in range(key_num-1):
        par = tmp[j]
        for k in range(j+1, key_num):
            if rank[k] < cur[k] + par and par > 0:
                cur[k] = rank[k]
                par -= rank[k] - cur[k]
            else:
                cur[k] += par
                par = 0
                break
if sum(cur) == 2**n:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=input().split()
c=list(map(int,c))
c.sort(reverse=True)
nc=len(c)
#最初の親のセット
pk=c[0]
p=[]
p.append(pk)
flag=False
#親の数だけ親より小さい最大数をｓから探しPの後ろに接続、
#同時にsは親最大数に置換する
#親未満のものがなくなるか　ｐの長さがｓと同じになったら終了

for i in range(n) :   
  np=len(p)             #現在の親の数
  for ip in range(np):  #親の数だけ繁殖
    flag=False
    c.sort(reverse=True)
  # print(len(p),c)
    for ic in range(len(p),nc): #全個体リストから親未満のSを探索
      if p[ip]>c[ic]:    #繁殖可能
        flag=True        
        p.append(c[ic])  #ｐの後ろに子供を連けつ
        c[ic]=pk         #sにマーク
        break  #次の親判定に
    #for end---------------
    if flag==False:# 繁殖可能でない親が判明 終了する   
      break
  #for end-----------------
  if flag==False:# 繁殖可能でない親が判明 終了する
    break
#while end------------------
if flag==True:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
def main():
    inf = 10 ** 9 + 5
    n = int(input())
    n2 = 2 ** n
    s = list(map(int, input().split()))
    s.sort(reverse=True)
    # print(s)
    pp = [s[0]]
    s[0] = inf
    for _ in range(n):
        np = pp[:]
        while pp:
            p = pp.pop()
            i = 1
            while 1:
                if s[i] < p:
                    np.append(s[i])
                    s[i] = inf
                    break
                else:
                    i += 1
                if i == n2:
                    print("No")
                    exit()
        pp = np
    print("Yes")

main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
c=input().split()
c=list(map(int,c))
c.sort(reverse=True)
nc=len(c)
#最初の親のセット
pk=c[0]
p=[]
p.append(pk)
flag=False
#親の数だけ親より小さい最大数をｓから探しPの後ろに接続、
#同時にsは親最大数に置換する
#親未満のものがなくなるか　ｐの長さがｓと同じになったら終了
i=1
while len(p)*2<=nc :    #この施行での個体数が全個体数を超えない
  flag=False
  np=len(p)             #現在の親の数
  for ip in range(np):  #親の数だけ繁殖
    for ic in range(nc): #全個体リストから親未満のSを探索
      if p[ip]>c[ic]:    #繁殖可能
        flag=True        
        p.append(c[ic])  #ｐの後ろに子供を連けつ
        c[ic]=pk         #sにマーク
        break
    #for end---------------
    if flag==False:#繁殖可能な個体がない   
      break
  #for end-----------------
#  print(len(p))
#  print(p)
#  print(c)
  if flag==False:#繁殖可能な個体がない
    break
#while end------------------
if nc==len(p) and flag==True:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline())
S = list((int(wd) for wd in stdin.readline().split()))

slime = {}
for s in S:
    if s in slime:
        slime[s] += 1
    else:
        slime[s] = 1
        pass
    pass

key = list(slime.keys())
key.sort()
key.reverse()

slime_list = []
for k in key: slime_list += [slime[k]]
#print(slime_list)

cur = [1] + [0] * (len(slime_list)-1)
for n in range(N):
    #print(cur)
    post = list(cur)
    amari = 0
    for i in range(len(post)-1):
        post[i+1] += cur[i] + amari
        if post[i+1] > slime_list[i+1]:
            amari = post[i+1] - slime_list[i+1]
            post[i+1] = slime_list[i+1]
        else:
            amari = 0
            pass
        pass
    cur = post
    pass
#print(cur, amari)
if slime_list == post:
    print('Yes')
else:
    print('No')
    pass

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    global s

    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        k = len(s)
        dropped = set()
        # print(parents)
        for p in parents:
            oldK = k
            k = bisect.bisect(s[:k], p - 1) - 1
            # print("Old", oldK, k, s[k], p)
            if k == -1:
                print("No")
                exit(0)

            newparents.append(s[k])
            dropped.add(k)
        s = [x for i, x in enumerate(s) if i not in dropped]

        parents = sorted(newparents, reverse=True)

    # print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        for p in reversed(parents):
            k = bisect.bisect(s, p - 1) - 1
            if k == -1:
                print("No")
                exit(0)
            bisect.insort(newparents, s[k])
            s.pop(k)
        parents = newparents

    # print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())
s = list(map(int, input().split(" ")))
# n = 18
# s = list(reversed(range(1, 2 ** n + 1)))

s = sorted(s)
from collections import deque

def solve():
    parents = [s[-1]]
    s.pop()

    for i in range(n):
        newparents = list(parents)
        # print(parents)
        for p in parents:
            k = bisect.bisect(s, p - 1) - 1
            # print(p, s, k)
            if k == -1:
                print("No")
                exit(0)
            newparents.append(s[k])
            s.pop(k)
        parents = sorted(newparents, reverse=True)

    # print(parents)
    # print(k)
    if k == len(s):
        print("Yes")
    else:
        print("No")
solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
S = sorted([int(x) for x in input().split()])

Slimes = [S.pop(-1)]

flag = True
for i in range(1, N + 1):
    newSlimes = []
    for j in Slimes:
        idx = bisect.bisect_left(S, j)
        if idx == 0:
            flag = False
            break
        newSlimes.append(S.pop(idx-1))
    if not flag:
        break
    Slimes.extend(newSlimes)

print('Yes' if flag else 'No')

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
input = sys.stdin.readline

N = int(input())
A = sorted(map(int,input().split()),reverse=True)

USED=[0]*(1<<N)
USED[0]=1

for i in range(N):
    NOW=0
    k=0
    BUSED=copy.deepcopy(USED)
    for j in range(1<<i):
        while BUSED[k]==0:
            k+=1
        while USED[NOW]==1 or A[k]<=A[NOW]:
            NOW+=1

            if NOW==1<<N:
                print("No")
                sys.exit()

        USED[NOW]=1
        k+=1


print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = sorted(list(map(int, input().strip().split())), reverse=True)
    check = [False] * (2**N)
    now = []
    now.append([s[0], 1])
    check[0] = True
    ok = True
    for i in range(N):
        next_ = []
        for j in range(len(now)):
            hp, start = now[j]
            ok = False
            for k in range(start, 2**N):
                if s[k] < hp and not check[k]:
                    check[k] = True
                    next_.append([s[k], k+1])
                    ok = True
                    break
            if not ok:
                break
        now += next_
        if not ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
S = sorted([int(x) for x in input().split()])

Slimes = [[S.pop(-1)]]

flag = True
for i in range(1, N + 1):
    Slimes.append([])
    for j in range(i):
        for k in Slimes[j]:
            idx = bisect.bisect_left(S, k)
            if idx == 0:
                flag = False
                break
            Slimes[i].append(S.pop(idx-1))
        if not flag:
            break
    if not flag:
        break

print('Yes' if flag else 'No')

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

input = sys.stdin.readline


def main():
    n = int(input())
    s = list(map(int, input().split()))
    ans = []

    s = list(sorted(s, reverse=True))

    ans.append(s.pop(0))

    while len(s):

        tmp = []
        for parent in ans:
            for i in range(len(s)):
                if parent > s[i]:
                    child = s.pop(i)
                    tmp.append(child)
                    break
            else:
                print('No')
                sys.exit()

        ans = ans + tmp

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * 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

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


def compress(li, origin=0):
    """
    座圧
    :param li:
    :param int origin:
    :rtype: list of int
    """
    *ret, = map({v: i + origin for i, v in enumerate(sorted(set(li)))}.__getitem__, li)
    return ret


def bisect_left_callable(fn, x, lo, hi):
    """
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


N = int(sys.stdin.readline())
S = list(map(int, sys.stdin.readline().split()))


def solve(S):
    S = compress(S, origin=1)
    S.sort(reverse=True)

    # bit[i]: サイズが i 以下のスライムの数
    bit = BinaryIndexedTree(size=max(S) + 1)
    for s in S:
        bit.add(s, 1)

    slimes = [S[0]]
    bit.add(S[0], -1)

    for _ in range(N):
        cnt = len(slimes)
        for i in range(cnt):
            # slimes[i] より小さい、一番大きいスライムを作る
            smallers = bit.sum(slimes[i] - 1)
            if smallers == 0:
                return False
            # 作れたら1減らす
            s = bisect_left_callable(bit.sum, smallers, lo=0, hi=slimes[i])
            slimes.append(s)
            bit.add(s, -1)
    return True


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

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N,*S = map(int, open(0).read().split())
    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        lg = len(g)
        for p in g[:lg]:
            for i in range(len(S)-1,-1,-1):
                s = S[i]
                if p > s:
                    g.append(s)
                    del S[i]
                    break
            else:
                print('No')
                sys.exit()
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N,*S = map(int, open(0).read().split())
    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        lg = len(g)
        for p in g[:lg]:
            for i in range(len(S)-1,-1,-1):
                s = S[i]
                if s != -1 and p > s:
                    g.append(s)
                    S[i] = -1
                    break
            else:
                print('No')
                sys.exit()
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    N,*S = map(int, open(0).read().split())
    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        g.sort(reverse=True)
        c = []
        for p in g:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    c.append(s)
                    S.pop(-(si+1))
                    break
            else:
                print('No')
                sys.exit()
        g.extend(c)
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

N,*S = map(int, open(0).read().split())
S = sorted(S)

g = [S.pop(-1)]

for gen in range(N):
    g.sort(reverse=True)
    for p in g[:2**gen]:
        for si, s in enumerate(S[::-1]):
            if p > s:
                g.append(s)
                S.pop(-(si+1))
                break
        else:
            print('No')
            sys.exit()
print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    g = [S.pop(-1)]

    for gen in range(N):
        g.sort(reverse=True)
        for p in g[:2**gen]:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    g.append(s)
                    S.pop(-(si+1))
                    break
            else:
                print('No')
                sys.exit()
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    g = [S.pop(-1)]

    for gen in range(N):
        g.sort(reverse=True)
        for p in g[:2**gen]:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    g.append(s)
                    del S[-(si+1)]
                    break
            else:
                print('No')
                sys.exit()
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    g = [S.pop(-1)]

    for gen in range(N):
        for p in g[:2**gen]:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    g.append(s)
                    del S[-(si+1)]
                    break
            else:
                print('No')
                sys.exit()
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        parents = g[:]
        for p in parents:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    g.append(s)
                    del S[-(si+1)]
                    break
            else:
                print('No')
                sys.exit()
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections

def main():
    N,*S = map(int, open(0).read().split())

    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        g = sorted(g, reverse=True)
        parents = g[:]
        for p in parents:
            for si, s in enumerate(S[::-1]):
                if p > s:
                    g.append(s)
                    del S[-(si+1)]
                    break;
            else:
                print('No')
                sys.exit()
    print('Yes')

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = int(input())
    s = list(map(int, input().split()))
    ans = []

    s = list(sorted(s, reverse=True))

    ans.append(s.pop(0))

    while len(s):

        tmp = []
        for parent in ans:
            for i in range(len(s)):
                if parent > s[i]:
                    child = s.pop(i)
                    tmp.append(child)
                    break
            else:
                print('No')
                sys.exit()

        ans = ans + tmp

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort()

    cur = []
    cur.append(S.pop(-1))

    for i in range(N):
        nxt = [j for j in cur]
        bl = len(S)
        for x in cur:
            bl = bisect.bisect_left(S,x,lo=0,hi=bl) - 1
            if bl==-1:
                return("No")
            else:
                nxt.append(S.pop(bl))
        nxt.sort(reverse=True)
        cur = [j for j in nxt]
    return("Yes")

if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())
    S = [int(s) for s in input().split()]
    S.sort()

    cur = []
    cur.append(S.pop(-1))

    for i in range(N):
        nxt = [j for j in cur]
        for x in cur:
            bl = bisect.bisect_left(S,x)
            if bl==0:
                return("No")
            else:
                nxt.append(S.pop(bl-1))
        cur = [j for j in nxt]
    return("Yes")

if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split(' ')))
a.sort(reverse = True)
 
 
fathers = [a.pop(0)]
for _ in range(N):
    sons = []
    b = []

    for father in fathers:
        while a:
            x = a.pop(0)
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                continue
                
    a = b + a
    fathers += sons
    fathers.sort(reverse = True)
    


if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import bisect
 
N = int(input())
a = list(map(int,input().split(' ')))
a.sort(reverse = True)
 
 
fathers = [a.pop(0)]
for _ in range(N):
    sons = list()
    b = list()

    for father in fathers:
        while a:
            x = a.pop(0)
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = b + a
    fathers.extend(sons)
    fathers.sort(reverse = True)
    


if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
p = [S.pop(-1)]
r = S

for i in range(N):
    for p_ in p[::-1]:
        for r_ in r[::-1]:
            if r_ < p_:
                p.append(r_)
                r.remove(r_)
                break
    p.sort()

print("Yes" if len(r)==0 else "No")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
p = [S.pop(-1)]
r = S

for i in range(N):
    for p_ in p[::-1]:
        for k in range(len(r)):
            if r[-k-1] < p_:
                p.append(r.pop(-k-1))
                break
    p.sort()

print("Yes" if len(r)==0 else "No")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)
p = [S.pop(0)]
r = S

for i in range(N):
    np = []
    for p_ in p:
        for k in range(len(r)):
            if r[k] < p_:
                np.append(r.pop(k))
                break
    p += np
    p.sort(reverse=True)

print("Yes" if len(r)==0 else "No")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)
p = [S.pop(0)]
c = S
f = False

for i in range(N):
    np = []
    nc = []
    for p_ in p:
        for k in range(len(c)):
            if c[k] < p_:
                np.append(c.pop(k))
                f = True
                break
        if f == False:
            print("No")
            exit(0)
        f = False
    p += np
    p.sort(reverse=True)

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split(' ')))
a.sort(reverse = True)


fathers = [a.pop(0)]
for _ in range(N):
    sons = list()
    for father in fathers:
        for index,value in enumerate(a):
            if father > value:
                sons.append(a.pop(index))
                break

    fathers.extend(sons)

if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)
p = [S.pop(0)]
c = S
f = False

for i in range(N):
    np = []
    nc = []
    for j in range(len(p)):
        for k in range(len(c)):
            if c[k] < p[j]:
                np.append(c.pop(k))
                f = True
                break
        if f == False:
            print("No")
            exit(0)
        f = False
    p += np
    p.sort(reverse=True)

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split(' ')))
a.sort()


fathers = [a.pop()]
for _ in range(N):
    sons = list()
    for father in fathers:
        son = a.pop(bisect.bisect_left(a,father)-1)
        
        if son >= father:
            pass
        else:
            sons.append(son)

    fathers.extend(sons)
    
if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=list(map(int,input().split()))
S.sort()
S.reverse()
p = [S.pop(0)]
c = S
f = False

for i in range(N):
    np = []
    nc = []
    for j in range(len(p)):
        for k in range(len(c)):
            if c[k] < p[j]:
                np.append(c.pop(k))
                f = True
                break
        if f == False:
            print("No")
            exit(0)
        f = False
    p += np
    p.sort()
    p.reverse()

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import bisect

N = int(input())
a = list(map(int,input().split(' ')))
a.sort()

def do(n,fathers):
       
    if n == N:
        return
    
    sons = list()
    for father in fathers:
        son = a.pop(bisect.bisect_left(a,father)-1)
        
        if son >= father:
            return
        else:
            sons.append(son)

    fathers.extend(sons)
    do(n+1,fathers)
    


fathers = [a.pop()]
do(0, fathers) 

if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import deque
import heapq
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S,key=lambda x:x)
    # debug(S,'S')
    live = [S[-1]]
    S.pop()
    # iはステップ
    for i in range(N):
        # 各スライムに生んでもらう
        livenext = [l for l in live]
        for l in live:
            borned = False
            for j in range(len(S)-1, -1, -1):
                if l > S[j]:
                    livenext.append(S[j])
                    S.remove(S[j])
                    borned = True
                    break
            if not borned:
                print("No")
                exit()
        live = livenext
    if len(S) == 0:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)
from collections import deque
import heapq
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    S = [int(a) for a in input().split()]
    S = sorted(S,key=lambda x:x)
    # debug(S,'S')
    live = [S[-1]]
    S.pop()
    # iはステップ
    for i in range(N):
        # 各スライムに生んでもらう
        livenext = live.copy()
        for l in live:
            borned = False
            for j in range(len(S)-1, -1, -1):
                if l > S[j]:
                    # debug((l,S[j]),'parent, child')
                    livenext.append(S[j])
                    S.remove(S[j])
                    borned = True
                    break
            if not borned:
                print("No")
                exit()
        live = livenext
    if len(S) == 0:
        print("Yes")
    else:
        print("No")



if __name__ == "__main__":
    main()