#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
//最大公約数
long gcd(long a, long b){
if (a%b==0){
return b;
}
else{
return gcd(b,a%b);
}
}
//最小公倍数
long lcm(long a, long b){
return (a*b) / gcd(a,b);
}
typedef long long ll;
int a[101];
int main(){
int k, t;
cin >> k >> t;
REP(i,t) scanf("%d", &a[i]);
int f = 0;
REP(i,t){
if (a[i] < k/t){
f = 1;
break;
}
}
if (t == 1) cout << k-1 << endl;
else{
if (f == 0) cout << 0 << endl;
else{
int ans = -1;
sort(a,a+t);
int sum = 0;
REP(i,t-1) sum += a[i];
int i = 1;
while (ans > i || ans == -1){
ans = a[t-1] - i - sum*i;
i++;
}
cout << ans << endl;
}
}
return 0;
}
./Main.cpp: In function ‘int main()’:
./Main.cpp:37:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i,t) scanf("%d", &a[i]);
^