AtCoder Beginner Contest 163 - Homework

Takahashi has N days of summer vacation.
His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.
He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.
What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?
If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

-----Constraints-----
 - 1 \leq N \leq 10^6
 - 1 \leq M \leq 10^4
 - 1 \leq A_i \leq 10^4

-----Input-----
Input is given from Standard Input in the following format:
N M
A_1 ... A_M

-----Output-----
Print the maximum number of days Takahashi can hang out during the vacation, or -1.

-----Sample Input-----
41 2
5 6

-----Sample Output-----
30

For example, he can do the first assignment on the first 5 days, hang out on the next 30 days, and do the second assignment on the last 6 days of the vacation. In this way, he can safely spend 30 days hanging out.

Source: atcoder | Difficulty: EASY


Solutions:
(N, M) = map(int, input().split())
m = sum(list(map(int, input().split())))
if N - m >= 0:
	print(N - m)
else:
	print('-1')


(n, m) = map(int, input().split())
A = sum(list(map(int, input().split())))
print(max(n - A, -1))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
print(n - sum(a) if n - sum(a) >= 0 else -1)


(N, M, *A) = map(int, open(0).read().split())
print(max(N - sum(A), -1))


(N, M) = map(int, input().split())
lsA = list(map(int, input().split()))
sumA = sum(lsA)
print(max(-1, N - sumA))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
print(max(n - sum(a), -1))


(a, b) = map(int, input().split())
c = sum(map(int, input().split()))
print(max(a - c, -1))


(n, _, *a) = map(int, open(0).read().split())
print(max(-1, n - sum(a)))


(N, M) = map(int, input().split())
(*A,) = map(int, input().split())
a = sum(A)
ans = max(-1, N - a)
print(ans)


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
print(max(-1, n - sum(ar)))


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print(max(n - sum(l), -1))


(N, M) = map(int, input().split())
A = [int(i) for i in input().split()]
for i in range(M):
	N -= A[i]
if N >= 0:
	print(N)
else:
	print(-1)


(n, m) = map(int, input().split())
(*a,) = map(int, input().split())
ans = n - sum(a)
print([-1, ans][ans >= 0])


(n, m) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
print(max(-1, n - sum(arr)))


(N, M) = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)
print(max(N - a_sum, -1))


from numpy import cumsum
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l = cumsum(l)[-1]
if n < l:
	print('-1')
else:
	print(n - l)


(N, M) = map(int, input().split())
x = sum(map(int, input().split()))
print(N - x if N >= x else -1)


def __starting_point():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = n - sum(A)
	if ans >= 0:
		print(ans)
	else:
		print(-1)
__starting_point()


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
sa = sum(A)
print(max(-1, N - sa))


(N, M) = map(int, input().split())
A_li = list(map(int, input().split()))
print(max(N - sum(A_li), -1))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in a:
	n -= i
if n >= 0:
	print(n)
else:
	print('-1')


(n, m) = map(int, input().split())
for num in input().split():
	n -= int(num)
print(n if n >= 0 else -1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print('-1' if sum(l) > n else n - sum(l))


(n, m) = map(int, input().split())
asum = sum(map(int, input().split()))
print(-1 if n < asum else n - asum)


(N, M) = map(int, input().split())
A = map(int, input().split())
b = N - sum(A)
print(-1 if b < 0 else b)


(M, N) = map(int, input().split())
l = list(map(int, input().split()))
print(max(M - sum(l), -1))


(n, m) = tuple(map(int, input().split()))
x = list(map(int, input().split()))
for _ in x:
	n -= _
if n >= 0:
	print(n)
else:
	print(-1)


(N, M) = list(map(int, input().split()))
day = list(map(int, input().split()))
total = 0
for i in range(M):
	total += day[i]
if N >= total:
	print(N - total)
else:
	print('-1')


(n, m) = map(int, input().split(' '))
alist = list(map(int, input().split(' ')))
asum = sum(alist)
if n - asum >= 0:
	print(n - asum)
else:
	print(-1)


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
print(N - sum(A) if sum(A) <= N else -1)


(n, m, *a) = map(int, open(0).read().split())
s = sum(a)
print(max(-1, n - s))


(n, m) = map(int, input().split())
days = input().split()
x = 0
for day in days:
	x = x + int(day)
if x <= n:
	print(n - x)
else:
	print(-1)


a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
x = a[0] - sum(b)
if x < 0:
	print(-1)
else:
	print(x)


(n, m) = map(int, input().split())
aa = list(map(int, input().split()))
homework = sum(aa)
if n < homework:
	print(-1)
else:
	print(n - homework)


(n, m) = map(int, input().split())
s = sum(tuple(map(int, input().split())))
print(-1 if s > n else n - s)


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

def answer(N: int, M: int, A: list) -> int:
	A = sum(A)
	if N < A:
		return -1
	else:
		return N - A
print(answer(N, M, A))


n = int(input().split()[0])
print(max(-1, n - sum(map(int, input().split()))))


I = lambda : list(map(int, input().split()))
(n, m) = I()
n = n - sum(I())
print(n if n >= 0 else -1)


(N, M) = map(int, input().split())
A = [int(i) for i in input().split()]
print(max(-1, N - sum(A)))


(a, b) = map(int, input().split())
c = [int(x) for x in input().split()]
s = sum(c)
print(max(a - s, -1))


(d, n) = map(int, input().split())
a = list(map(int, input().split()))
print(max(-1, d - sum(a)))


radi = input()
list = radi.split(' ')
N = int(list[0])
days = input()
total = 0
a = days.split(' ')
for items in a:
	total += int(items)
if total > N:
	print(-1)
else:
	print(N - total)


(N, M) = map(int, input().split())
A = list(map(int, input().split()))
r = N - sum(A)
if r < 0:
	r = -1
print(r)


(n, t) = map(int, input().split())
s = n - sum(map(int, input().split()))
if s < 0:
	print(-1)
else:
	print(s)


(N, M) = map(int, input().split())
(*A,) = map(int, input().split())
print(max(-1, N - sum(A)))


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
print(max(-1, n - sum(lst)))


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
t = sum(A)
print(n - t if t <= n else '-1')


(N, M) = map(int, input().split())
print(max(N - sum([int(x) for x in input().split()]), -1))


s = 0
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(0, len(a)):
	s = s + a[i]
if s > n:
	print(-1)
	return
print(n - s)


(N, M) = list(map(int, input().split()))
A_list = []
for i in range(1, M + 1):
	A_list.append('A_' + str(i))
A_list = list(map(int, input().split()))
answer = N - sum(A_list)
if answer >= 0:
	print(answer)
else:
	print(-1)


(N, M) = map(int, input().split())
work = list(map(int, input().split()))
if N >= sum(work):
	answer = N - sum(work)
else:
	answer = '-1'
print(answer)


(N, M) = map(int, input().split())
(*A,) = map(int, input().split())
for a in A:
	N -= a
print(-1 if N < 0 else N)


print(max(-1, list(map(int, input().split()))[0] - sum(map(int, input().split()))))


(N, _) = map(int, input().split())
s = sum(map(int, input().split()))
print(N - s if N >= s else -1)


(n, m) = map(int, input().split())
li = list(map(int, input().split()))
print(max(n - sum(li), -1))


import sys
(N, M) = map(int, input().split())
A = list(map(int, input().split()))
sum_day = sum(A)
ans = N - sum_day
if ans < 0:
	print(-1)
else:
	print(ans)


(n, m) = map(int, input().split())
s = sum(list(map(int, input().split())))
print(max(-1, n - s))


(n, m) = map(int, input().split())
a = map(int, input().split())
ans = max(-1, n - sum(a))
print(ans)


(n, m, *l) = [int(i) for i in open(0).read().split()]
print(max(-1, n - sum(l)))


(n, m) = map(int, input().split())
a_map = map(int, input().split())
print(max(-1, n - sum(a_map)))


def readinput():
	(n, m) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	return (n, m, a)

def main(n, m, a):
	days = sum(a)
	if days > n:
		return -1
	else:
		return n - days

def __starting_point():
	(n, m, a) = readinput()
	ans = main(n, m, a)
	print(ans)
__starting_point()


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
print(max(-1, n - sum(a)))


list = []
(n, m) = map(int, input().split())
a = input().split()[0:m]
for num in a:
	num = int(num)
	list.append(num)
answer = n - sum(list)
if n < sum(list):
	answer = -1
print(answer)


(n, m) = map(int, input().split())
aa = list(map(int, input().split()))
print(max(-1, n - sum(aa)))


(n, _) = map(int, input().split())
A = map(int, input().split())
print(max(n - sum(A), -1))


(m, n, *aa) = map(int, open(0).read().split())
ans = m - sum(aa)
if ans < 0:
	print(-1)
else:
	print(ans)


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(n, m) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
tmp = 0
res = 0
for i in range(m):
	tmp += A[i]
res = max(-1, n - tmp)
print(res)


R = lambda : map(int, input().split())
(n, m) = R()
print(max(n - sum(R()), -1))


(n, _) = map(int, input().split())
a = n - sum(map(int, input().split()))
print(-1 if a < 0 else a)


def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(map(int, input().split()))

def i_row(N):
	return [int(input()) for _ in range(N)]

def i_row_list(N):
	return [list(map(int, input().split())) for _ in range(N)]
(dnum, hwnum) = i_map()
hws = i_list()
if dnum >= sum(hws):
	ans = dnum - sum(hws)
	print(ans)
else:
	print(-1)


(n, m) = map(int, input().split())
sum_a = sum(map(int, input().split()))
print(max(n - sum_a, -1))


(n, m) = map(int, input().split())
works = map(int, input().split())
print(max(n - sum(works), -1))


(N, M, *A) = map(int, open(0).read().split())
play = N - sum(A)
print(play if play >= 0 else -1)


(n, m) = map(int, input().split())
A = list(map(int, input().split()))
day = 0
for i in range(len(A)):
	day = day + A[i - 1]
if n < day:
	print(-1)
else:
	ans = n - day
	print(ans)


def N():
	return int(input())

def L():
	return list(map(int, input().split()))

def NL(n):
	return [list(map(int, input().split())) for i in range(n)]
mod = pow(10, 9) + 7
import sys
import math
import collections
(n, m) = L()
a = L()
print(max(n - sum(a), -1))


def my_input():
	return list(map(int, input().split()))
(n, _) = my_input()
ans = n - sum(my_input())
print(ans if ans >= 0 else -1)


def i():
	return [int(x) for x in input().split()]
(n, m) = i()
c = sum(i())
print(n - c if n >= c else -1)


(a, _) = map(int, input().split())
li = [int(x) for x in input().split()]
s = sum(li)
print(max(a - s, -1))


(n, m, *a) = map(int, open(0).read().split())
a = sum(a)
print(n - a if n >= a else -1)


(n, m) = map(int, input().split())
a_list = list(map(int, input().split()))
a_total = sum(a_list)
ans = n - a_total
if ans < 0:
	print(-1)
else:
	print(ans)


(n, m) = tuple(map(int, input().split(' ')))
print(max(n - sum(map(int, input().split(' '))), -1))


(n, _) = map(int, input().split())
a = n - eval(input().replace(' ', '+'))
print([-1, a][a >= 0])


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
sum = 0
for i in range(m):
	sum += l[i]
if sum > n:
	print(-1)
else:
	print(n - sum)


(n, m) = map(int, input().split())
f = n - sum(map(int, input().split()))
print(-1 if f < 0 else f)


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
s = sum(arr)
print(max(-1, n - s))


(n, m, *A) = map(int, open(0).read().split())
print(max(n - sum(A), -1))


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = sum(c)
print(a - d if a - d >= 0 else -1)


(a, b) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
print(max(a - sum(arr), -1))


(N, _) = input().split()
a = map(int, input().split())
d = int(N) - sum(a)
if d < 0:
	print(-1)
else:
	print(d)


(n, m) = map(int, input().split())
a = map(int, input().split())
d = n - sum(a)
if d < 0:
	d = -1
print(d)


(n, m) = map(int, input().split())
xdays = sum(list(map(int, input().split())))
print(max(-1, n - xdays))


l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
print(max(-1, l[0] - sum(m)))


(N, M) = map(int, input().split())
t = N - sum((int(x) for x in input().split()))
print(-1 if t < 0 else t)


def main():
	(n, m) = list(map(int, input().split()))
	homeworks = tuple(map(int, input().split()))
	print(max(-1, n - sum(homeworks)))
	return

def __starting_point():
	main()
__starting_point()


(N, X) = map(int, input().split())
Y = N - sum(map(int, input().split()))
print(('-1', Y)[Y >= 0])


a = input().split()
b = input().split()
suma = 0
for x in range(int(a[1])):
	suma += int(b[x])
dias = int(a[0]) - suma
if dias < 0:
	print('-1')
else:
	print(dias)


(N, M) = map(int, input().split())
As = list(map(int, input().split()))
print(max(N - sum(As), -1))


def inpl():
	return list(map(int, input().split()))
(N, M) = inpl()
print(max(-1, N - sum(inpl())))


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
print(max(n - sum(data), -1))


(N, M) = map(int, input().split())
S = sum(map(int, input().split()))
print(max(-1, N - S))


(n, m) = map(int, input().split())
a = [int(s) for s in input().split()]
days = n - sum(a)
print(days) if days >= 0 else print(-1)


(N, _) = map(int, input().split())
z = N - eval(input().replace(*' +'))
print(z if 0 <= z else -1)


(N, M) = map(int, input().split())
ans = N - sum(list(map(int, input().split())))
print(max(ans, -1))


(n, m) = list(map(int, input().split()))
a = [int(x) for x in input().split()]
ans = n - sum(a)
print(str(max(ans, -1)))


(n, _) = map(int, input().split())
ans = n - sum(map(int, input().split()))
if ans < 0:
	ans = -1
print(ans)


(N, M) = list(map(int, input().split()))
num_list = list(map(int, input().split()))
x = N - sum(num_list)
if x >= 0:
	print(x)
else:
	print(-1)


(N, _) = map(int, input().split())
A = sum(map(int, input().split()))
print(N - A) if N >= A else print(-1)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
	n -= a[i]
print(max(n, -1))


(a, b) = list(map(int, input().split()))
s = sum(list(map(int, input().split())))
print(max(a - s, -1))


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
print(max(-1, n - sum(t)))


(N, M) = map(int, input().split())
la = list(map(int, input().split()))
print(max(N - sum(la), -1))


(N, K) = [int(s) for s in input().split()]
ls = [int(s) for s in input().split()]
print(max([N - sum(ls), -1]))


def __starting_point():
	(N, M) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	if N >= sum(li):
		print(N - sum(li))
	else:
		print('-1')
__starting_point()


(n, m) = map(int, input().split())
a = sum(map(int, input().split()))
print([n - a, -1][n < a])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(N, M) = na()
A = na()
print(max(N - sum(A), -1))


def calc(n, m):
	holidays = n
	a = list((int(v) for v in input().split()))
	ans = holidays - sum(a)
	return ans if ans >= 0 else -1

def main():
	(n, m) = list(map(int, input().split()))
	return calc(n, m)

def __starting_point():
	print(main())
__starting_point()


(n, m) = map(int, input().split())
tot = sum(map(int, input().split()))
print(max(-1, n - tot))


(a, b) = map(int, input().split())
li = list(map(int, input().split()))
sum = 0
for i in li:
	sum += i
if a > sum:
	print(a - sum)
elif a == sum:
	print(0)
else:
	print(-1)


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
s = sum(l)
print(max(-1, n - s))


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
print(n - sum(a) if n >= sum(a) else -1)