Problem:


Score : 200 points

Problem Statement

Rng is preparing a problem set for a qualification round of CODEFESTIVAL.

He has N candidates of problems. The difficulty of the i-th candidate is D_i.

There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems.

Determine whether Rng can complete the problem set without creating new candidates of problems.

Constraints

1 \leq N \leq 200,000

1 \leq D_i \leq 10^9

1 \leq M \leq 200,000

1 \leq T_i \leq 10^9

All numbers in the input are integers.

Partial Score

100 points will be awarded for passing the test set satisfying N \leq 100 and M \leq 100.

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N
M
T_1 T_2 ... T_M

Output

Print YES if Rng can complete the problem set without creating new candidates of problems; print NO if he cannot.

Sample Input 1

5
3 1 4 1 5
3
5 4 3

Sample Output 1

YES

Sample Input 2

7
100 200 500 700 1200 1600 2000
6
100 200 500 700 1600 1600

Sample Output 2

NO

Not enough 1600s.

Sample Input 3

1
800
5
100 100 100 100 100

Sample Output 3

NO

Sample Input 4

15
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
9
5 4 3 2 1 2 3 4 5

Sample Output 4

YES



Sample input:
5
3 1 4 1 5
3
5 4 3


Sample output:
YES

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
D=Counter((list(map(int,input().split()))))
M=int(input())
T=Counter((list(map(int,input().split()))))

for i in range(len(D)):
    x=sorted([i for i in D.items()])

for j in range(len(T)):
    y=sorted([j for j in T.items()])

if N<M or len(x)<len(y):
    print("NO")
else:
    cnt=0
    for i in range(len(x)):
        for j in range(len(y)):
            if x[i][0]==y[j][0] and x[i][1]>=y[j][1]:
                cnt+=1
    print("YES" if cnt==len(y) else "NO")

Submission status: Time Limit Exceeded

Solution code:
# 15
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
m = I()
t = LI()
d.sort()
t.sort()
ans = 'YES'
i = 0
for elem in d:
    # print(elem, t[0])
    if t[0] == elem:
        t.pop(0)
    if len(t) == 0:
        break
if len(t) != 0:
    ans = 'NO'
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
cnt = {}
for i in d:
  if i not in cnt:
    cnt[i] = d.count(i)
m = int(input())
t = list(map(int,input().split()))
flag = True
for i in t:
  if i in cnt:
    if cnt[i]>0:
      cnt[i] -= 1
    else:
      flag = False
      break
  else:
    flag = False
    break
if flag:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
*D, = map(int, input().split())
M = int(input())
*T, = map(int, input().split())

B = set(T)

if sum([D.count(b) >= T.count(b) for b in B]) == len(B):
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))

c=collections.Counter(t)
cc=list(c.items())
#print(cc)
if n < m:
    print('NO')
else:
    for i in range(len(cc)):
        if d.count(cc[i][0])<cc[i][1]:
            print('NO')
            sys.exit()
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys

n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))

if n < m:
    print('NO')
else:
    for i in range(m):
        if i!=m-1:
            if t[i]==t[i+1]:
                continue
            else:
                if t.count(t[i])>d.count(t[i]):
                    print('NO')
                    sys.exit()
        else:
            if t.count(t[i])>d.count(t[i]):
                print('NO')
                sys.exit()
            
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
ans = 'YES'
for i in range(M):
    t = T[i]
    if t in D:
        D.remove(t)
    else:
        ans = 'NO'
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
ans = 'YES'
for i in range(M):
    t = T[i]
    if t in D:
        D.remove(t)
    else:
        ans = 'NO'
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))

ans = "YES"
for t in T:
    if t not in d: 
        ans = "NO"
        break
    d.pop(d.index(t))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
d = input().split()
m = int(input())
t = input().split()
c = 0
for i in range(m):
  if t[i] not in d:
    print("NO")
    sys.exit()
  else:
    d.remove(t[i])
    c += 1
if c == m:
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = input().split()
m = int(input())
t = input().split()
c = 0
for i in range(m):
  if t[i] in d:
    c += 1
    d.remove(t[i])
if c == m:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
D = l()
M = k()
T = l()

for i in T:
    if i in D:
        D.remove(i)
    else:
        print("NO")
        sys.exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import fractions
import itertools

def solve():
    n = int(input())
    d = list(map(int, input().split()))
    m = int(input())
    t = list(map(int, input().split()))
    t = collections.Counter(t)
    for i in t:
        if t[i] > d.count(i):
            print("NO")
            break
    else:
        print("YES")
    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = LIST()
m = INT()
t = LIST()
for x in t:
    if(x in d):
        d.remove(x)
    else:
        print("NO")
        exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr


N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))



li = intersect_list(D,T)

T.sort()
li.sort()
if T == li:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
CT = Counter(T)
D.sort()
T.sort()
ans = 'YES'

for i,j in CT.items():
  if D.count(i) < j:
    ans = 'NO'
    break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

D.sort()
T.sort()
ans = 'YES'

for t in T:
  b = bisect_left(D,t)
  if D[b] != t:
    ans = 'NO'
    break
  else:
    D = D[b+1:]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

D.sort()
T.sort()

ans = 'YES'

for t in T:
  b = bisect_left(D,t)
  if D[b] != t:
    ans = 'NO'
    break
  else:
    D.pop(b)
    D = D[b:]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

D.sort()
T.sort()

ans = 'YES'

for t in T:
  b = bisect_left(D,t)
  if D[b] != t:
    ans = 'NO'
    break
  else:
    D.pop(b)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
import collections
#d=collections.Counter(d)
t=collections.Counter(t)
for i in t.items():
  if i[0] not in d:
    print("NO")
    break
  if i[0] in d and i[1]>d.count(i[0]):
    print("NO")
    break
else:
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
for i in range(m):
  if t.count(t[i])>d.count(t[i]):
    print("NO")
    break
else:
  print("YES")

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
N=int(input())
D = list(map(int, input().split()))
M=int(input())
T = list(map(int, input().split()))
new_D=sorted(D)
new_T=sorted(T)
#print(new_D[0])
for i in range(len(T)):
    if new_D.count(new_T[i])==0:
        print("NO")
        sys.exit()
    if new_D.count(new_T[i])>=1:
        new_D.remove(new_T[i])
        #print(new_D.count(new_T[i]))
    
print("YES")

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
n = int(input())
D = sorted(list(map(int, input().split())))
m = int(input())
T = list(map(int, input().split()))
for t in T:
	while t:
		i = bisect_left(D, t)
		if i == n or D[i] != t:
			print("NO")
			exit()
		else:
			t -= D[i]
			n -= 1
			D.pop(i)
else:
	print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
D = sorted(list(map(int, input().split())))[::-1]
m = int(input())
T = sorted(list(map(int, input().split())))[::-1]
for t in T:
	for i, d in enumerate(D):
		if d <= t:
			D[i] = 0
			t -= d
			if t == 0:
				break
	if t:
		print("NO")
		exit()
else:
	print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
D = sorted(list(map(int, input().split())))[::-1]
m = int(input())
T = sorted(list(map(int, input().split())))[::-1]
for t in T:
	for i, d in enumerate(D):
		if d <= t:
			D[i] = 0
			t -= d
	if t:
		print("NO")
		exit()
else:
	print("YES")

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
d_li = list(map(int,input().split()))
m = int(input())
t_li = list(map(int,input().split()))

t_counter = Counter(t_li)
t_li = t_counter.most_common()
t_len = len(t_li)
for i in range(t_len):
    dum = t_li[i][0]
    if d_li.count(dum) >= t_li[i][1]:
        pass
    else:
        print("NO")
        exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
m = int(input())
tl = list(map(int,input().split()))
for t in tl:
  if t in d:
    d.remove(t)
  else:
    print('NO')
    exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))

c = collections.Counter(lm)

for i in c.keys():
    if ln.count(i) < c[i]:
        print("NO")
        exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))

c = collections.Counter(lm)

for i in range(len(c)):
    if ln.count(list(c.keys())[i]) < c[list(c.keys())[i]]:
        print("NO")
        exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = sorted(list(map(int, input().split())))
m = int(input())
lm = sorted(list(map(int, input().split())))

for i in range(m):
    j = 0
    for j in range(n):
        if lm[i] == ln[j]:
            del ln[j]
            n -= 1
            break
        elif lm[i] < ln[j] or lm[i] > ln[n-1]:
            print("NO")
            exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ln = list(map(int, input().split()))
m = int(input())
lm = list(map(int, input().split()))

for i in range(m):
    if lm[i] in ln:
        ln.remove(lm[i])
    else:
        print("NO")
        exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    dlis = []
    tlis = []
    dlis = list(map(int, input().split()))
    m = int(input())
    tlis = list(map(int, input().split()))
    dlis.sort()
    for t in tlis:
        if t in dlis:
            #print(t,tlis, dlis)
            dlis.remove(t)
        else:
            #print(t,tlis, dlis)
            print("NO")
            exit()
    print("YES")


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    def main():

        n=int(input())
        d=list(map(int,input().split()))
        m=int(input())
        t=list(map(int,input().split()))
        from collections import Counter
        dd=Counter(d)
        tt=Counter(t)
        ddkey=list(dd.keys())
        ddvalue=list(dd.values())
        for x,y in tt.items():
            flag=True
            if x in ddkey and ddvalue[ddkey.index(x)]>=y:
                continue
            else:
                return 'NO'
        return 'YES'
    print(main())
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        n=int(input())
        d=list(map(int,input().split()))
        m=int(input())
        t=list(map(int,input().split()))
        from collections import Counter
        dd=Counter(d)
        tt=Counter(t)
        ddl=list(dd.keys())
        for x,y in tt.items():
            flag=True
            for j,k in dd.items():
                if x==j :
                    if y<=k:
                        flag=False
                        break
                    else:
                        return 'NO'
            if flag:
                return 'NO'
        return 'YES'
    print(main())
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    dl=list(map(int,input().split()))
    m=int(input())
    tl=list(map(int,input().split()))
    ans='YES'
    for i in tl:
        if i not in dl:
            ans='NO'
            break
        if i in dl:
            dl.remove(i)
    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

for t in T:
    if not D:
        break
    if t in D:
        D.remove(t)
    else:
        print("NO")
        break
else:
    print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
D = list(map(int,input().split()))
m = int(input())
T = list(map(int,input().split()))
cnt = 0
for t in T:
  if t in D:
    cnt += 1
    D.remove(t)
if cnt == m:
  print('YES')
else:
  print('NO')

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    D = [int(_) for _ in input().split()]
    M = int(input())
    T = [int(_) for _ in input().split()]

    if N < M:
        print("NO")
        return

    for i in range(M):
        target = T[i]
        if D.count(target) >= 1:
            D.remove(target)
        else:
            print("NO")
            return
    
    print("YES")


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]
D2 =D

cnt=0
for t in set(T):
    if t in set(D):
        cnt+=1
if cnt !=len(set(T)):
    print('NO')
    exit()
for i in T:
    try:
        D2.remove(i)
    except:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
for t in T:
    if D.count(t) < T.count(t):
        print('NO')
        sys.exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]
D2 =D
for i in T:
    try:
        D2.remove(i)
    except:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
for t in T:
    if t in D:
        D.remove(t)
    elif t not in D:
        print("NO")
        sys.exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

m = int(input())

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

d.sort()

t.sort()

index = 0

for i in t:
    flag = True
    while index < len(d):
        if i == d[index]:
            d.pop(index)
            flag = False
            break
        else:
            index += 1
    if flag:
        print('NO')
        exit()

print('YES')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D_list = list(map(int,input().split()))
M = int(input())
T_list = list(map(int,input().split()))

ans = 'YES'
for i in T_list:
    if not D_list.count(i) >= T_list.count(i):
        ans = 'NO'
        print(ans)
        break
if ans == 'YES':
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split(" ")))
M = int(input())
T = list(map(int, input().split(" ")))
count = 0
T.sort()
D.sort()
if M <= N:
    for i in T:
        if i in D:
            D.remove(i)
            count += 1
        else:
            print("NO")
            break
    else:
        print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split(" ")))
M = int(input())
T = list(map(int, input().split(" ")))
count = 0
if N >= M:
    for i in T:
        if i in D:
            D.remove(i)
            count += 1
        else:
            break

if count == M:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

d = collections.Counter(D)
t = collections.Counter(T)

ans = 'YES'
for i in range(len(t)):
    if list(t.values())[i] > d[list(t.keys())[i]]:
        ans = 'NO'

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# CODE FESTIVAL 2017 予選 B: B – Problem Set
N = int(input())
D = [int(s) for s in input().split()]
M = int(input())
T = [int(s) for s in input().split()]

canDo = 'YES'

for t in T:
    if t not in D:
        canDo = 'NO'
        break
    else:
        D[D.index(t)] = 0

print(canDo)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
d = sorted(list(map(int, input().split())))
m = int(input())
t = sorted(list(map(int, input().split())))
yes = True
for i in t:
    index = bisect_left(d, i)
    if d[index] != i:
        yes = False
        break
    d.pop(index)
if yes:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
d = sorted(list(map(int, input().split())))
m = int(input())
t = sorted(list(map(int, input().split())))
yes = True
for i in t:
    index = bisect_left(d, i)
    if d[index] != i:
        yes = False
        break
    del d[index]
if yes:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrD = list(map(int,input().split()))
M = int(input())
arrT = list(map(int,input().split()))

for dif in arrT:
    if dif in arrD:
        arrD.remove(dif)
    else:
        print("NO")
        exit()

print("YES")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

for i in range(m):
    if t[i] not in d:
        break
    else:
        d.pop(d.index(t[i]))
print("YES" if len(d) == n-m else "NO")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))

for i in range(M):
  if T[i] in D:
    D.remove(T[i])
  else:
    print('NO')
    exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
d_li = list(map(int,input().split()))
d_li.sort()
m = int(input())
t_li = list(map(int,input().split()))
t_li.sort()
for t in t_li:
    ind = bisect.bisect_left(d_li, t)
    if ind > len(d_li) -1:
        print('NO')
        exit()
    if d_li[ind] == t:
        d_li = d_li[ind+1:]
        #print(d_li)
    else:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
d_li = list(map(int,input().split()))
d_li.sort()
m = int(input())
t_li = list(map(int,input().split()))
t_li.sort()
for t in t_li:
    ind = bisect.bisect_left(d_li, t)
    if ind > len(d_li) -1:
        print('NO')
        exit()
    if d_li[ind] == t:
        d_li = d_li[ind+1:]
        #print(d_li)
    else:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_li = list(map(int,input().split()))
d_li.sort()
m = int(input())
t_li = list(map(int,input().split()))
t_li.sort()
for t in t_li:
    if t in d_li:
        d_li.remove(t)
    else:
        print('NO')
        exit()
print('YES')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
N=list(map(int,input().split()))
m=int(input())
M=list(map(int,input().split()))

for i in M:
  if i in N:
    N.remove(i)
  else:
    print("NO")
    exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    M=int(input())
    T=[int(_) for _ in input().split()]

    for t in T:
        if t in D:
            D.remove(t)
        else:
            print("NO")
            break
    else:
        print("YES")

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
if n < m:
    print("NO")
else:
    for i in t:
        if t.count(i) > d.count(i):
            print("NO")
            exit()
    print("YES")