Language: C++

#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll K, T;
    cin >> K >> T;
    vector<ll> a(T);
    rep(i, T) cin >> a[i];
    ll ma = *max_element(all(a));
    print(max(ma - 1 - (K-ma),(ll)0));
    return 0;
}
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll K, T;
    cin >> K >> T;
    vector<ll> a(T);
    rep(i, T) cin >> a[i];
    ll ma = *max_element(all(a));
    print(max(ma - 1 - (K-ma),(ll)0));
    return 0;
}


Compiler output:
a.cc:96:4: error: redefinition of 'll gcd(ll, ll)'
   96 | ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
      |    ^~~
a.cc:34:4: note: 'll gcd(ll, ll)' previously defined here
   34 | ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
      |    ^~~
a.cc:97:4: error: redefinition of 'll lcm(ll, ll)'
   97 | ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
      |    ^~~
a.cc:35:4: note: 'll lcm(ll, ll)' previously defined here
   35 | ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
      |    ^~~
a.cc:100:4: error: redefinition of 'll nCrModp(ll, ll, ll)'
  100 | ll nCrModp(ll n, ll r, ll p)
      |    ^~~~~~~
a.cc:38:4: note: 'll nCrModp(ll, ll, ll)' previously defined here
   38 | ll nCrModp(ll n, ll r, ll p)
      |    ^~~~~~~
a.cc:115:5: error: redefinition of 'int main()'
  115 | int main()
      |     ^~~~
a.cc:53:5: note: 'int main()' previously defined here
   53 | int main()
      |     ^~~~