Problem:


Score : 200 points

Problem Statement

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 1

41 2
5 6

Sample Output 1

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.

Sample Input 2

10 2
5 6

Sample Output 2

-1

He cannot finish his assignments.

Sample Input 3

11 2
5 6

Sample Output 3

0

He can finish his assignments, but he will have no time to hang out.

Sample Input 4

314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3

Sample Output 4

9



Sample input:
41 2
5 6


Sample output:
30

Submission status: Accepted

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

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

for i in range(M):
    N -= A[i]

if N < 0:
    print(-1)
else:
    print(N)

Submission status: Accepted

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

ans = N - sum(A)
if ans < 0:
    print("-1")
else:
    print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=list(map(int,input().split()))
s=sum(A)
print(N-s if N>=s else -1)

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    a = list(map(int, input().split()))

    print(max(-1, N-sum(a)))
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)

if N >= sumA:
    print(N - sum(A))
else:
    print(-1)

Submission status: Accepted

Solution code:
import numpy as np
import math as mt
N,M=map(int, input().split())
A=list(map(int,input().split()))
day=N-sum(A)
if day<0:
    print(-1)
else:
    print(day)

Submission status: Accepted

Solution code:
i = input()
j = input()
lista = i.split()
listb = j.split()
nokori = int(lista[0])
for i in range(int(lista[1])):
    nokori -= int(listb[i])
if nokori >= 0:
    print(nokori)
else:
    print(-1)

Submission status: Accepted

Solution code:
n, _ = map(int, input().split())
A = map(int, input().split())

print(max(n - sum(A), -1))

Submission status: Accepted

Solution code:
N,M = map(int,input().rstrip().split(" "))
k = list(map(int,input().rstrip().split(" ")))
for i in range(M):
    N -= k[i]
if N >= 0:
    print(N)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
def main():
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    s=sum(A)
    if n>=s:
        print(n-s)
    else:
        print(-1)
main()

Submission status: Accepted

Solution code:
N , M  = map ( int , input().strip().split(" ") ) ;
arr  = list (  map ( int , input().strip().split(" ") ) ) ;
r = N - sum ( arr ) ;

r = -1 if r< 0 else r ; 
print ( r ) ;

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = map(int, input().split())
a_sum = sum(a)
ans = n - a_sum
if ans >= 0:
    print(ans)
else:
    print("-1")

Submission status: Accepted

Solution code:
N, M = [int(n) for n in input().split()]
A = sum([int(n) for n in input().split()])
print(N-A if A <= N else -1)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
Am = [int(i) for i in input().split()]
days = sum(Am)
print(max(N - days, -1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc163/abc163_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    A = i2nn()
    hw = sum(A)
    play = N - hw
    if play >= 0:
        print(play)
    else:
        print(-1)
    return

main()

Submission status: Accepted

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

res = sum(A) - N

if res>0:
    print(-1)
else:
    print(-1*res)

Submission status: Accepted

Solution code:
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M = iim()
    A = sum(iim())

    ans = N - A
    if ans < 0:
        ans = -1
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
l=list(map(int,input().split()))
if a-sum(l)>=0:
    print(a-sum(l))
else:
    print(-1)

Submission status: Accepted

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

if sum(a) > n:
  print("-1")
else:
  print(n - sum(a))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = map(int, input().split())

ans = n - sum(a)

if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

if n-sum(a_list) >= 0:
    print(n-sum(a_list))
    
else:
    print(-1)

Submission status: Accepted

Solution code:
from sys import stdin


def main():

    N, _ = [int(x) for x in stdin.readline().rstrip().split()]

    a_lists = [int(x) for x in stdin.readline().rstrip().split()]

    sum_ = sum(a_lists)

    if N >= sum_:
        print(N-sum_)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

n=list(map(int,input().split()))
L=list(map(int,input().split()))
print(n[0]-sum(L) if n[0]-sum(L)>=0 else "-1")

Submission status: Accepted

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

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

ans = N-sum(A)

if ans < 0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

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

r = n-sum(a_list)
print(r if r >= 0 else -1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
day = N - sum(A)
if day < 0:
    print(-1)
else:
    print(day)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
AA = list(map(int,input().split()))
if sum(AA)>N:
    print(-1)
else:
    print(N-sum(AA))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
*a, = map(int, input().split())
ans = -1
if n >= sum(a):
    ans = n - sum(a)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
home = sum(A)
if N >= home:
    print(N - home)
else:
    print(-1)

Submission status: Accepted

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

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

    ss = sum(A)
    if ss > N:
        print(-1)
    else:
        print(N - ss)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list(map(int, input().split()))
a_sum = sum(a)

if n < a_sum:
    print(-1)
else:
    print(n - a_sum)

Submission status: Accepted

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

S=N-sum(A)

if S<0:
  print(-1)
else:
  print(S)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
a = list(map(int, input().split()))
if N < sum(a):
	print('-1')
else:
	print(N - sum(a))

Submission status: Accepted

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


def main():
  N, _ = map(int, input().split())
  S = sum(map(int, input().split()))

  if S > N:
    print(-1)
  else:
    print(N - S)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
A=sum(a)
if A<=n:
  print(n-A)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

Solution code:
N, M =map(int,input().split())
a = list(map(int, input().split(' ')))
j = sum(a)
print(max(N-j,-1))

Submission status: Accepted

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

import math

def main():
    n,m = map(int, input().strip().split())
    a_li = list(map(int, input().strip().split()))

    if n - sum(a_li) < 0:
        print(-1)
    else:
        print(n - sum(a_li))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
A = sum(int(x) for x in input().split())

print(max(N-A, -1))

Submission status: Accepted

Solution code:
def resolve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b=sum(a)
    if b>n:
        print(-1)
    else:
        print(n-b)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) > n:
    print(-1)
    exit()
print(n - sum(a))

Submission status: Accepted

Solution code:
n, m = map(int, input().split(" "))
a_list = list(map(int, input().split(" ")))

print(max(n - sum(a_list), -1))

Submission status: Accepted

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

S = sum(A)

print(N-S if N-S>=0 else -1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    SA = sum(tuple(map(int, input().split())))
    if SA > N:
        print(-1)
    else:
        print(N-SA)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

playdays = N - sum(A)

if playdays < 0:
    print(-1)
else:
    print(playdays)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N , M = map(int, input().split())
    A_list = [A for A in input().split()]
    A_list = list(map(int, A_list))

    total = sum(A_list)
    day = N - total

    if total > N :
        print("-1")
    else :
        print(day)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = n - sum(map(int, input().split()))

print(-1) if ans < 0 else print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

rtn = n - np.sum(a)
if rtn < 0:
    rtn = -1
print(rtn)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A_list=[int(i) for i in input().split()]
A_sum=sum(A_list)
if N-A_sum>0:
  print(N-A_sum)
elif N-A_sum==0:
  print('0')
else:
  print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

ans=n-sum(a)
if ans<0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
days_needed=sum(A)
if(days_needed>n):
    print(-1)
else:
    print(n-days_needed)

Submission status: Accepted

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

print(n-sum(a) if n-sum(a) >= 0 else -1)

Submission status: Accepted

Solution code:
import math
#sys.exit()
#sorted( ,reverse=True)
#R = int(input())
N,M= map(int, input().split())
A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)

#print('Yes')
#print('No')
if N-sum(A)>= 0:
    print(N-sum(A))
else:
    print(-1)

Submission status: Accepted

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

s = sum(A)

if s > n:
    print("-1")
else:
    print(n-s)

Submission status: Accepted

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

b = sum(a)

if b > n:
    print(-1)
else:
    print(n-b)

Submission status: Accepted

Solution code:
import sys
n, m = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

ans = n - sum(A)

if ans < 0:
    ans = -1

print(ans)

Submission status: Accepted

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

for i in range(m):
    n-=a[i]

if n>=0:
    print(n)
else:
    print(-1)

Submission status: Accepted

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

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

cnt_day = sum(a_list)

if N >= cnt_day:
    print(N-cnt_day)
else:
    print(-1)

Submission status: Accepted

Solution code:
s = input().split(" ")
N = int(s[0])
M = s[1]
s = input().split(" ")
A = []
sum = 0
for w in s:
    A.append(int(w))
    sum += int(w)

if sum <= N:
    print(N - sum)
else:
    print(-1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
if (N - sum(A) >= 0):
    print(N-sum(A))
else:
    print("-1")

Submission status: Accepted

Solution code:
def b():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    play = N - sum(A)
    if play < 0:
        print(-1)
    else:
        print(play)


##########
if __name__ == "__main__":
    b()

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n,m = map(int,input().strip().split())
    a = list(map(int, input().strip().split()))

    print(max(n-sum(a),-1))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = (int(i) for i in input().split())  
A = [int(i) for i in input().split()] 

sub = N - sum(A)

if sub < 0:
  print(-1)
else:
  print(sub)

Submission status: Accepted

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

if N - sum(A) >= 0:
    print(N - sum(A))
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

A_sum = sum(A_list)
if A_sum <= N:
    print(N-A_sum)
else:
    print(-1)

Submission status: Accepted

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

leisure = N - sum(A)
if leisure < 0:
  print("-1")
else:
  print(leisure)

Submission status: Accepted

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

ans = N - sum(a)
print(ans if ans>=0 else -1)

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

if n -sum(a) < 0:
  print(-1)
  quit()
print(n-sum(a))

Submission status: Accepted

Solution code:

N,M = list(map(int , input().split()))
A = list(map(int , input().split()))
S = sum(A)
if N >= S:
    print(N-S)
else:
    print("-1")

Submission status: Accepted

Solution code:
#B
n, m = map(int, input().split())
a = list(map(int, input().split()))
study = sum(a)
if n < study:
    print(-1)
else:
    print(n-study)

Submission status: Accepted

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

for ai in a:
    n -= ai
if n >= 0:
    print(n)
else:
    print(-1)

Submission status: Accepted

Solution code:
days, num_homewrok = [int(i) for i in input().split()]
homeworks = [int(i) for i in input().split()]
sum_homeworks = sum(homeworks)

ans = days - sum_homeworks if days >= sum_homeworks else -1

print(ans)

Submission status: Accepted

Solution code:
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,m=INPUT()
A=INPUT()
sum=0
for ele in A:
    sum+=ele
if n>=sum:
    print(n-sum)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
if n-s<0:print(-1)
else:print(n-s)

Submission status: Accepted

Solution code:
#!python3

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


def main():
    s = sum(A)
    ans = max(-1, N - s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    As = list(map(int, input().split()))
    sm = sum(As)

    if (n-sm < 0):
        print(-1)
    else:
        print(n-sm)
    
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))

if sum(b)<=a[0]:
    print(a[0]-sum(b))
else:
    print(-1)

Submission status: Accepted

Solution code:
s = list(map(int, input().split()))
a = list(map(int, input().split()))
n=s[0]
m=s[1]
for i in range (m):
    n-=a[i]
if n<0:
    print(-1)
else:
    print(n)

Submission status: Accepted

Solution code:
N , M = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) > N:
    print(-1)
else:
    print(N - sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,M=map(int,input().split())
A=list(map(int,input().split()))
if N-sum(A)>=0:
    print(N-sum(A))
else:
    print(-1)

Submission status: Accepted

Solution code:
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n, a):
    res = n-sum(a)
    if res < 0:
        res = -1
    return res


if __name__ == "__main__":
    n, m = inums()
    a = inums()
    print(solve(n, a))

Submission status: Accepted

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

a.sort(reverse=True)
b = 1
su = 0
for i in range(M):
  su += a[i]
  if su > N:
    b = -1
    
  
print(N - su if b > 0 else '-1')

Submission status: Accepted

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

ans = n - sum(a)
print(ans if ans >= 0 else -1)

Submission status: Accepted

Solution code:

def resolve():
    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    if sum(a) > n:
        print(-1)
        return
    print(n - sum(a))

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

ans = N-sum(A)
if ans<0:
    print("-1")
else:
    print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lst = list(map(int, input().split()))
if sum(lst) > n:
    print(-1)
else:
    print(n - sum(lst))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [int(a) for a in input().split()]

result = N - sum(A)

if result >= 0:
  print(result)
else:
  print(-1)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
Asum = sum(A)
print(max(-1, N - Asum))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) > N:
    print(-1)
else:
    print(N-sum(A))

Submission status: Accepted

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

SUM = sum(A)

if N - SUM < 0:
    print(-1)
else:
    print(N - SUM)

Submission status: Accepted

Solution code:
def solve(n, m, arr):
    ans = n - sum(arr)
    if ans >= 0:
        print(ans)
    else:
        print(-1)
if __name__ == "__main__":
    n, m = map(int, input().split(' '))
    arr = [int(s) for s in list(input().split())]
    solve(n, m, arr)

Submission status: Accepted

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

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

day = N - sum(A)

if day < 0:
  print(-1)
else:
  print(day)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
ans=n-sum(a)

print(ans if ans>=0 else -1)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = list(map(int, input().split()))
rem = n-sum(A)

print(max(rem, -1))

Submission status: Accepted

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


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

    hw = sum(A)

    if N >= hw:
        print(N-hw)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys,math
def input():
    return sys.stdin.readline()[:-1]
N,M = map(int,input().split(' '))
l = list(map(int, input().split()))

ANS = 0

for i in range(M):
    ANS += l[i]
if ANS>N:
    print(-1)
else:
    print(N-ANS)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

if N >= sum(A):
    print(N-sum(A))
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

n, m = inpl()
a = inpl()
if n - sum(a) < 0:
    print("-1")
else:
    print(n-sum(a))

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    # N, M = 41, 2
    # A = [5,6]

    max = sum(A)
    ans = N - max
    if ans < 0:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = N - sum(dl)

if ans >= 0:
  print(ans)
else:
  print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = [int(x) for x in input().split()]
    l = [int(x) for x in input().split()]
    play = n - sum(l)
    if play < 0:
        return - 1
    else:
        return play


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