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:
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 (i in d) == False or t.count(i) > d.count(i):
            print("NO")
            exit()
    print("YES")

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
d = [int(i) for i in input().split()] # 配列で数字

m = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()]

def bs(nums, target):
    l = 0
    r = len(nums) - 1
    while l <= r:
        mid = (l + r) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] > target:
            r = mid - 1
        else:
            l = mid + 1
    return -1

if n < m:
    print('NO')
else:
    d.sort()
    for p in t:
        r = bs(d, p)
        if r == -1:
            print('NO')
            break
        else:
            del d[r]
    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()))
a=True
for i in t:
    if i in d:
        j=d.index(i)
        d=d[:j]+d[j+1:]
    else:
        a=False
        break
print('YES' if a else 'NO')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=list(map(int, input().split()))
M=int(input())
T=A=list(map(int, input().split()))
if N<M:
    print('NO')
else:
    tf=1
    for i in range(0,M):
        c=T[i] in D
        if c==True:
            f=D.index(T[i])
            D[f]=0
        else:
            tf=0
    if tf==1:
        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
  

for i in range(len(t)):
  try:
    d.remove(t[i])
    count += 1
  except:
    print('NO')
    break
    
if count == m:
  print('YES')

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    ind = 0
    length = len(D)
    for t in T:
        if ind == length:
            print('NO')
            return
        else:
            index = bisect_left(D[ind:], t)
            if D[ind:][index] != t:
                print('NO')
                return
            else:
                ind += index + 1
    print('YES')
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    D = sorted(map(int, input().split()))
    m = int(input())
    T = sorted(map(int, input().split()))
    ind = 0
    for t in T:
        if ind == len(D):
            print('NO')
            return
        for i, d in enumerate(D[ind:]):
            if t == d:
                ind += i + 1
                break
        else:
            print('NO')
            return
    print('YES')
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
D = sorted(list(map(int, input().split())))
m = int(input())
T = sorted(map(int, input().split()))
for t in T:
    if t in D:
        D = D[D.index(t)+1:]
    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())

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

D = sorted(D)
T = sorted(T)


begin = 0
ok = 9
for i in T:
    if i in D[begin:]:
        index_ = D[begin:].index(i)
        begin += index_ + 1
    else:
        ok = 1
        break

if ok == 1:
    print("NO")
else:
    print("YES")

Submission status: Time Limit Exceeded

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

dic = {}
for i in d:
    if i in dic.keys():
        dic[i] += 1
    else:
        dic[i] = 1
for i in t:
    if i in dic.keys():
        dic[i] -= 1
        if dic[i] == 0:
            del(dic[i])
    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())
t=list(map(int,input().split()))
for i in t:
  if i in d:
    del d[d.index(i)]
  else:
    print("NO")
    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()]
d.sort()
t.sort()
idx = 0
while len(t) != 0 and idx < n:
    if d[idx] == t[0]:
        t.pop(0)
    elif d[idx] > t[0]:
        print("NO")
        exit()
    idx += 1
print("YES") if len(t) == 0 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()))

x = 0
for i in range(m):
    if t[i] in d:
        x += 1
        d.remove(t[i])
if x == m:
    print('YES')
else:
    print('NO')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=int(input())
pl=list(map(int,input().split()))
for i in range(m):
  if not pl[i] in set(l):
    print('NO')
    break
  else:
    l.remove(pl[i])
  if i==m-1:
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
dp=input().split()
m=int(input())
tp=input().split()
d=dict()

ans="YES"

for di in dp:
    if di in d:
        d[di]+=1
    else:
        d[di]=1

for ti in tp:
    if ti not in dp or d[ti]==0:
        ans="NO"
        break
    else:
        d[ti]-=1
print(ans)

Submission status: Time Limit Exceeded

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

ans="YES"

for di in dp:
    if di in d:
        d[di]+=1
    else:
        d[di]=1

for ti in tp:
    if ti not in dp or d[ti]==0:
        ans="NO"
        break
    else:
        d[ti]-=1
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()))
D.sort()
T.sort()
if n<=m:
    if D==T:
        print('YES')
        exit()
    else:
        print('NO')
        exit()

r = 'YES'
for i in range(m):
    if T[i] in D:
        idx = D.index(T[i])
        D = D[idx+1:]
    else:
        r = 'NO'
        break
print(r)

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

r = 'YES'
for i in range(m):
    if T[i] in D:
        D.remove(T[i])
    else:
        r = 'NO'
        break
print(r)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

n = int(input())
d = [int(x) for x in input().split()]
m = int(input())
t = [int(x) for x in input().split()]
for et in t:
    if et not in d:
        print("NO")
        exit()
    d.remove(et)
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()))
s_T = set(T)
Flg = "YES"

for val in s_T:
    if(T.count(val) > D.count(val)):
        Flg = "NO"
        break
print(Flg)

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()))
Flg = "YES"

for i in range(M):
    if(T.count(T[i]) > D.count(T[i])):
        Flg = "NO"
        break
print(Flg)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dlis = list(map(int, input().split()))
m = int(input())
tlis = list(map(int, input().split()))
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return result
lis = list_difference(tlis, dlis)
if lis:
    print("NO")
else:
    print("YES")

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
d = list(map(int,stdin.readline().rstrip().split()))
m = int(stdin.readline().rstrip())
t = list(map(int,stdin.readline().rstrip().split()))
d.sort()
t.sort()
li = []
for key, value in groupby(t):
    li.append((key,len(list(value))))
for i in li:
    if d.count(i[0]) < i[1]:
        print("NO")
        exit()
print("YES")

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()))
Tcount = Counter(T)
flag = 'YES'
for n,c in Tcount.items():
    if c > D.count(n):
        flag = 'NO'
        break
print(flag)

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()))
Tcount = Counter(T)
flag = 'YES'
for n,c in Tcount.items():
    if c > D.count(n):
        flag = 'NO'
print(flag)

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

d.sort()

def solve(num,s,l):
	if s == l:
		if d[s] == num:
			return s
		else:
			return -1
	elif s+1 == l:
		if d[s] == num:
			return s
		elif d[l] == num:
			return l
		else:
			return -1

	c = s + (l-s)//2
	if d[c] == num:
		return c
	elif d[c] < num:
		return solve(num,c,l)
	else:
		return solve(num,s,c)

for i in range(m):
	A = solve(t[i],0,n-1)
	if A == -1:
		print("NO")
		sys.exit()
	else:
		d.pop(A)
		n -= 1

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

d.sort()
t.sort()
cond = 1
cnt = 0
for i in range(m):
	tmp_t = t[i]
	while d != []:
		tmp_d = d.pop(0)
		if tmp_d < tmp_t:
			continue
		elif tmp_d == tmp_t:
			cnt += 1
			break
		else:
			cond = 0
			break
	if cond == 0:
		print("NO")
		sys.exit()

if cnt == m:
	print("YES")
else:
	print("NO")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
flag = False
cnt = 0
for i in range(m):
    if L2.count(L2[i]) <= L1.count(L2[i]):
        flag = True
        cnt +=1
    else:
        flag = False
if flag and cnt == len(L2):
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
L1 = list(map(int,input().split()))
m = int(input())
L2 = list(map(int,input().split()))
for i in range(m):
    if L2[i] in L1:
        L1.remove(L2[i])
    elif L2[i] not in L1:
        print("NO")
        exit()
if len(L1) >= 0:
    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()))

flag = 0
for t in T:
    try:
        D.remove(t)
    except ValueError:
        flag = 1
        print("NO")
        break
if flag == 0:
    print("YES")

Submission status: Time Limit Exceeded

Solution code:
import collections

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


if n < m:
    print('NO')
    exit()

c = collections.Counter(a)
d = collections.Counter(b)

for i, j in d.items():
    for x, y in c.items():
        flag = False
        if i == x and j > y:
            print('NO')
            exit()
        elif i == x:
            flag = True
            break
    if flag is False:
        print('NO')
        exit()

print('YES')

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

Dnew = [elem for elem in D if elem in T]

c1 = Counter(Dnew)
c2 = Counter(T)

flag = True
for key in c2:
    if c2[key] > c1[key]:
        flag = False
        break

if flag:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, D: "List[int]", M: int, T: "List[int]"):
    
    D.sort()
    T.sort()

    from bisect import bisect_left, bisect_right

    if M > N:
        print(NO)
        exit()
        

    for i in range(M):
        lf = bisect_left(D, T[i])
        ri = bisect_right(D, T[i])
        if lf != ri:
            D.pop(lf)
        else:
            print(NO)
            exit()

    print(YES)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    T = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, D, M, T)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, D: "List[int]", M: int, T: "List[int]"):
    
    D.sort()
    T.sort()

    from bisect import bisect_left, bisect_right

    for i in range(M):
        lf = bisect_left(D, T[i])
        ri = bisect_right(D, T[i])
        if lf != ri:
            D.pop(lf)
        else:
            print(NO)
            exit()

    print(YES)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    M = int(next(tokens))  # type: int
    T = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, D, M, T)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
import sys
input=sys.stdin.readline
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if i>0:
        if t[i]==t[i-1]:
            cnt-=1
            if d[cnt]==t[i]:
                d.pop(cnt)
                if i==m-1:
                    ans='YES'
            else:
                break
        else:
            cnt=bisect.bisect_right(d,t[i])-1
            if d[cnt]==t[i]:
                d.pop(cnt)
                if i==m-1:
                    ans='YES'
            else:
                break
    else:
        cnt=bisect.bisect_right(d,t[i])-1
        if d[cnt]==t[i]:
            d.pop(cnt)
            if i==m-1:
                ans='YES'
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
import sys
input=sys.stdin.readline
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    cnt=bisect.bisect_right(d,t[i])-1
    if d[cnt]==t[i]:
        d.pop(cnt)
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
import sys
input=sys.stdin.readline
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if d[bisect.bisect_right(d,t[i])-1]==t[i]:
        d.pop(bisect.bisect_right(d,t[i])-1)
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
import sys
input=sys.stdin.readline
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if d[bisect.bisect_right(d,t[i])-1]==t[i]:
        d.remove(t[i])
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
import sys
input=sys.stdin.readline
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if d[bisect.bisect_right(d,t[i])-1]==t[i]:
        d.remove(d[bisect.bisect_right(d,t[i])-1])
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import bisect
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
ans='NO'
d.sort()
for i in range(m):
    if d[bisect.bisect_right(d,t[i])-1]==t[i]:
        d.remove(d[bisect.bisect_right(d,t[i])-1])
        if i==m-1:
            ans='YES'
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

flag = 1
for elem in t:
    try:
        x = d.index(elem)
    except ValueError:
        flag = 0
        break
    d.remove(elem)

if flag == 0:
    print("NO")
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()))

f=True
for Ti in T:
    if D.count(Ti)<T.count(Ti):
        f=False
        break

print('YES' if f else 'NO')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import collections
import sys
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
cD = collections.Counter(D)
cT = collections.Counter(T)
d_key = list(cD.keys())
t_key = list(cT.keys())
d_val = list(cD.values())
t_val = list(cT.values())

for i in range(len(t_key)):
    if t_key[i] in d_key:
        a = d_key.index(t_key[i])
        if t_val[i] > d_val[a]:
            print("NO")
            sys.exit()
    else:
        print("NO")
        sys.exit()

print("YES")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
count = 0
for i in range(M):
    if T[i] in D:
        D.remove(T[i])
        count += 1

if count == M:
    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()))
for i in T:
  if i not in D:
    print("NO")
    exit()
  D.remove(i)
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()

a = 0
cnt = 0
last = t[-1]
for i in range(n):
    for j in range(a, m):
        if d[i] == t[j]:
            cnt += 1
            a = j+1
            break
        elif d[i] > last:
            break
        
if cnt == m:
    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()))

import  bisect

D.sort()
T.sort()
cnt=0
for i in range(M):
    a=bisect.bisect_right(D,T[i])
    b=bisect.bisect_left(D,T[i])
    if a-b>0:
        D.remove(D[a-1])
        cnt+=1
    else:
        print("NO")
        exit()

if cnt==M:
    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()))

import  bisect

D.sort()
T.sort()
cnt=0
for i in range(M):

    if bisect.bisect_right(D,T[i])-bisect.bisect_left(D,T[i])>0:
        D.remove(D[bisect.bisect_right(D,T[i])-1])
        cnt+=1
    else:
        print("NO")
        exit()

if cnt==M:
    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()))
sum = 0
for i in T:
  for j in range(N):
    if i == D[j]:
      D[j] = 0
      sum += 1
      break
if sum == M:
  print("YES")
else:
  print("NO")

Submission status: Time Limit Exceeded

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

for i in range(m):
    b2=bisect.bisect_right(d,t[i])
    #print(d,t,b2)
    if d[b2-1]!=t[i]:
        print('NO')
        break
    else:
        d=d[:b2-1]+d[b2:]
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[i] not in d:
        print('NO')
        break
    else:
        d.remove(t[i])
else:
    print('YES')

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n = int(input())
d = list(int(i) for i in input().split())
m = int(input())
t = list(int(i) for i in input().split())

for i in range(m):
  if t[i] in d:
    d.remove(t[i])
  else:
    print('NO')
    exit(0)

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(N):
  if D[i] in T:
    T.remove(D[i])
    D[i]=0
    if len(T)==0:
      break
if len(T)==0:
  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()))

for t in T:
  if t in D:
    D.remove(t)
  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())
t=list(map(int, input().split()))

d_dict={}
for dd in d:
    if dd not in d_dict:
        d_dict[dd]=d.count(dd)

for tt in t:
    if tt in d_dict and d_dict[tt]>0:
        d_dict[tt]-=1
    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())
t=list(map(int, input().split()))

d_dict={}
for dd in d:
    if dd not in d_dict:
        d_dict[dd]=d.count(dd)
t_dict={}
for tt in t:
    if tt not in t_dict:
        t_dict[tt]=t.count(tt)

for t_num in t_dict:
    if t_num in d_dict and d_dict[t_num]>= t_dict[t_num]:
        continue
    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())
t=list(map(int, input().split()))

for i in range(m):
    if d.count(t[i])>=t.count(t[i]):
        continue
    else:
        print("NO")
        exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
m=int(input())
t=sorted(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:
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:
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
count = 0
for t in T:
    if t in D:
        D.remove(t)
        count += 1
if count == M:
    print("YES")
else:
    print("NO")

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=int(input())
d=list(map(int,input().split()))
e=set(d)

for item in e:
  if d.count(item)>b.count(item):
    print("NO")
    exit()
    
print("YES")

Submission status: Time Limit Exceeded

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

for item in e:
  if r.count(item)<d.count(item):
    print("NO")
    exit()
print("YES")

Submission status: Time Limit Exceeded

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

for item in d:
  if item in r:
    r.remove(item)
  else:
    print("NO")
    exit()
print("YES")

Submission status: Time Limit Exceeded

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

for item in d:
  if item in r:
    r.remove(item)
  else:
    print("NO")
    exit()
print("YES")

Submission status: Time Limit Exceeded

Solution code:
N = input()
nums = list(map(int, input().split()))
nums.sort()
M = input()
tasks = list(map(int, input().split()))
tasks.sort()

ans = "YES"

for task in tasks:
    if task in nums:
        nums.remove(task)
    else:
        ans = "NO"
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
nums = list(map(int, input().split()))
M = input()
tasks = list(map(int, input().split()))

ans = "YES"

for task in tasks:
    if task in nums:
        nums.remove(task)
    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()))

for t in T:
    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 = sorted(list(map(int, input().split())))
m = int(input())
t = sorted(list(map(int, input().split())))

for i in t:
  if i in d:
    d.remove(i)
  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())
t = list(map(int, input().split()))

for i in t:
  if i in d:
    d.remove(i)
  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())
t = list(map(int,input().split()))

ans = "YES"
for i in t:
    if d.count(i) < t.count(i):
        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()))
s = set(t)
ans = "YES"
for i in s:
    if d.count(i) < t.count(i):
        ans = "NO"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  D = list(map(int,input().split()))
  m = int(input())
  T = list(map(int,input().split()))
  tmp = []
  for t in T:
    if t in D:
      D.remove(t)
      tmp.append(t)
  if T == tmp:
    print("YES")
  else:
    print("NO")

main()

Submission status: Time Limit Exceeded

Solution code:
def quick_sort(arr):
  left = []
  right = []
  if len(arr) <= 1:
    return arr

  # データの状態に左右されないためにrandom.choice()を用いることもある。
  # ref = random.choice(arr)
  ref = arr[0]
  ref_count = 0

  for ele in arr:
    if ele < ref:
      left.append(ele)
    elif ele > ref:
      right.append(ele)
    else:
      ref_count += 1
  left = quick_sort(left)
  right = quick_sort(right)
  return left + [ref] * ref_count + right

n = int(input())
ds = quick_sort(list(map(int,input().split())))
m = int(input())
ts = quick_sort(list(map(int,input().split())))

for t in ts:
  for d in ds:
    if d==t:
      ds.remove(t)
      break
    elif d < t:
      continue
    else:
      print('NO')
      exit(0)
print('YES')

Submission status: Time Limit Exceeded

Solution code:
def quick_sort(arr):
  left = []
  right = []
  if len(arr) <= 1:
    return arr

  # データの状態に左右されないためにrandom.choice()を用いることもある。
  # ref = random.choice(arr)
  ref = arr[0]
  ref_count = 0

  for ele in arr:
    if ele < ref:
      left.append(ele)
    elif ele > ref:
      right.append(ele)
    else:
      ref_count += 1
  left = quick_sort(left)
  right = quick_sort(right)
  return left + [ref] * ref_count + right

n = int(input())
ds = quick_sort(list(map(int,input().split())))
m = int(input())
ts = quick_sort(list(map(int,input().split())))

for t in ts:
  if t in ds:
    ds.remove(t)
  else:
    print('NO')
    exit(0)
print('YES')

Submission status: Time Limit Exceeded

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

for t in ts:
  if t in ds:
    ds.remove(t)
  else:
    print('NO')
    exit(0)
print('YES')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ds = list(map(int,input().split()))
m = int(input())
ts = list(map(int,input().split()))

for t in ts:
  if t in ds:
    ds.remove(t)
  else:
    print('NO')
    exit(0)
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()
def find(a, i):
    l = 0
    r = len(a)-1
    mid = (l+r)//2
    while l <= r:
        if i == a[mid]:
            return mid
        elif i < a[mid]:
            r = mid - 1
        else:
            l = mid + 1
        mid = (l+r)//2
    return -1

for i in range(M):
    j = find(D, T[i])
    if j == -1:
        print("NO")
        exit(0)
    D.pop(j)
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 t in T:
    if t in D:
        D.remove(t)
    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())
T = list(map(int,input().split()))

for d in D:
    if d in T:
        T.remove(d)

if T:
    print("NO")
else:
    print("YES")