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: Runtime Error

Solution code:
/**
 * Created By: Anonyman637
 * Created On: 4/19/2020 6:05:58 PM
 */

/* =============================================================================
   ================================== HEADERS ==================================
   ========================================================================== */

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

/* =============================================================================
   ================================= TYPEDEFS ==================================
   ========================================================================== */

typedef char i8;
typedef short i16;
typedef int i32;
typedef long long i64;

typedef unsigned char ui8;
typedef unsigned short ui16;
typedef unsigned int ui32;
typedef unsigned long long ui64;

typedef double db;
typedef long double ldb;

using namespace std;

/* =============================================================================
   ================================== MACROS ===================================
   ========================================================================== */

#ifdef DEBUG
#define debug(format, ...) printf(format, __VA_ARGS__)
#else
#define debug(format, ...) 
#endif

#define NOCSYNCIOS 1

#define FOREACH(it, cont) for (const auto& it : (cont)) 

#define ALL(cont) (cont).begin(), (cont).end()
#define RALL(cont) (cont).end(), (cont).begin()
#define SP(x) fixed << setprecision(x)

#define MP make_pair
#define PB push_back
#define fi first
#define se second

#define EPS 1e-9
#define MOD 1000000007

/* =============================================================================
   ================================== GLOBALS ==================================
   ========================================================================== */

const double pi=acos(-1.0);

/* =============================================================================
   =================================== SETUP ===================================
   ========================================================================== */

i32 setup() {

#if NOCSYNCIOS
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif

#if FILEIO
	#define FILEI
	if(freopen(OUTFILE, "w", stdout) == NULL) return 402;
#endif

#ifdef FILEI
	if(freopen(INFILE, "r", stdin) == NULL) return 401;
#endif

	return 0;
}


/* =============================================================================
   ================================= FUNCTIONS =================================
   ========================================================================== */

i32 main() {

	i32 errorInSetup = setup();
	if (errorInSetup) exit(errorInSetup);

	i32 i, t;
	i32 n, m;
	cin >> n >> m;
	i32 tini, total = 0;
	for (i = 0; i < m; ++i) {
		cin >> tini;
		total += tini;
	}

	if (n >= total) {
		printf("%d", n - total);
	} else {
		printf("-1");
	}



	
	return 0;
}

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
S = list[]
n = n - sum(S)
if n < 0:
  print("-1")
 else:
  print(n)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

vacation = n-sum(As)
if vacation < 0:
	print('-1')
else:
	print vacation

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  n,m=map(int,input().split())
  a=list(map(int,input().split())) #横一列リスト
  ans=0
  for i in range(m):
    ans+=a[i]
  if ans<=n:
      print(n-ans)
  else:
      print('-1')
main()

Submission status: Runtime Error

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

N = int(N)
M = int(M)
#print(N,M,A)

sum = 0
for i in A:
    sum += int(i)

#print(sum)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if __name__ == '__main__':
  main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

r = int(input())
x = math.pi

print(2*r*x)

Submission status: Runtime Error

Solution code:
n,m = map(int,input()) 
cnt = 0
for _ in range(m):
	cnt = cnt + int(input())
print(n-cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
atcoder-tools: The pre-rendered templates are not found.#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    play = N - sum(A)
    if play > -1:
        print(play)
    else:
        print(-1)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
n,k=map(int,input().split())
a=list(map(int,input().split())) #横一列リスト
ans=0
for i in range(n):
    ans+=a[i]
if ans<=n:
    print(n-ans)
else:
    print('-1')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
a,b=map(int,input().split)
c=input().split()
l=[]
for i in c:
  l.append(int(i))
if sum(l)>a:
  print(-1,end="")
else:
  print(a-sum(l),end="")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

homework=0

for a in A:
    homework+=a

if N>hemework:
    print(N-homework)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
def resolve():
    input().split()
    map(int, input().split())
    list(map(int, input().split()))
resolve()

Submission status: Runtime Error

Solution code:
import math
r = int(input())
print(2 * r * math.pi)

Submission status: Runtime Error

Solution code:
import math
R = int(input())
print(R*2*math.pi)

Submission status: Runtime Error

Solution code:
X=input().split()
N=int(X[0])
M=int(X[1])
A=list(map(int,input().split()))
y=N-sum(A)
if y>=0:
  return y
return -1

Submission status: Runtime Error

Solution code:
r = int(input())
pi = 3.14159265358979
print(2*r*pi)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

height = [input() for i in range(M)]
sum = N - sum(height)

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

Submission status: Runtime Error

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

s = sum(A)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
R = int(input())

print(2*R*3.1415926535897)

Submission status: Runtime Error

Solution code:
n,m=map(int,input())
a=list(map(int,input().split()))
b=sum(a)
print(max(0,n-b))

Submission status: Runtime Error

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

print(N-sum(A))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
r = int(input())
import math
print(2*r*math.pi)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
/usr/local/bin/python3.8 /Users/tmohiro/Desktop/Atcoder/ABC163/B.py
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
9

Process finished with exit code 0

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
# i=int(input())
#n,m=map(int, input().split())
r = int(input())
print(r*2*math.pi)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = [int(x) for x in input().split()]
    arr = [int(x) for x in input().split()]
    res = N - sum(arr)
    if res < 0:
        print(-1)
    else:

Submission status: Runtime Error

Solution code:
from b import resolve
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)
    def test_Sample_Input_1(self):
        input = """41 2
5 6"""
        output = """30"""
        self.assertIO(input, output)
    def test_Sample_Input_2(self):
        input = """10 2
5 6"""
        output = """-1"""
        self.assertIO(input, output)
    def test_Sample_Input_3(self):
        input = """11 2
5 6"""
        output = """0"""
        self.assertIO(input, output)
    def test_Sample_Input_4(self):
        input = """314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()

Submission status: Runtime Error

Solution code:
N,M = list(map(int, sys.stdin.readline().rstrip().split())) 
A = list(map(int, sys.stdin.readline().rstrip().split())) 

s = 0
for n in range(M):
  s += A[n]
  
s -= N
if s < 0:
  print(-1)
else:
  print(s)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ls = list(map(int,input().split()))
for a in range(ls):
  n -= a
print(max(-1,n))

Submission status: Runtime Error

Solution code:
def main():
    import sys
    import math
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    r = int(input())
    print(2*r*math.pi)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

days = sum(A)

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