#include<bits/stdc++.h> #define SINGLE_INPUT #define ull unsigned long long #define ll long long #define N 500005 #define MOD 998244353 usingnamespace std;
voidsol(){ int n; cin >> n; vector<int> a(n); for (int& i : a) cin >> i; int mx = *max_element(a.begin(), a.end()); if (mx == a[0] && count(a.begin(), a.end(), mx) == 1) { cout << "0\n"; } else { cout << mx - a[0] + 1 << "\n"; } }
#include<bits/stdc++.h> #define SINGLE_INPUT #define ull unsigned long long #define ll long long #define N 55 #define MOD 998244353 usingnamespace std;
vector<int> g[N];
int in[N];
voidsol(){ int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; in[y]++; } int ans = -1, cnt = 0; for (int i = 1; i <= n; i++) { if (in[i] == 0) { cnt++; ans = i; } } if (cnt == 1) cout << ans << "\n"; else cout << "-1\n"; }
#include<bits/stdc++.h> #define SINGLE_INPUT #define ull unsigned long long #define ll long long #define N 500005 #define MOD 998244353 usingnamespace std;
voidsol(){ int n; cin >> n; vector<ll> a(n); for (auto& i : a) cin >> i; sort(a.begin(), a.end()); ll sum = accumulate(a.begin(), a.end(), 0LL); vector<ll> b(n); for (int i = 0; i < n; i++) { if (i < sum % n) b[i] = 1; b[i] += sum / n; } reverse(b.begin(), b.end()); ll ans = 0; for (int i = 0; i < n; i++) { ans += max(0LL, a[i] - b[i]); } cout << ans << "\n"; }
#include<bits/stdc++.h> #define SINGLE_INPUT #define ull unsigned long long #define ll long long #define N 500005 #define MOD 998244353 usingnamespace std;
// #define MOD 1000000007 #define mint Modint<MOD> template <constint _MOD> structModint { int v; Modint() { v = 0; } Modint(longlong o) { v = o % _MOD; } intval(){ return v; } intpow(longlong o){ int ret = 1, tmp = v; while (o) { if (o & 1) ret = ((longlong)ret * tmp) % _MOD; o >>= 1; tmp = ((longlong)tmp * tmp) % _MOD; } return ret; } voidoperator=(longlong o) { v = o % _MOD; } booloperator==(longlong o) const { return v == o; } booloperator==(Modint o) const { return v == o.v; } booloperator!=(longlong o) const { return v != o; } booloperator!=(Modint o) const { return v != o.v; } booloperator<(longlong o) const { return v < o; } booloperator<(Modint o) const { return v < o.v; } booloperator>(longlong o) const { return v > o; } booloperator>(Modint o) const { return v > o.v; } booloperator<=(longlong o) const { return v <= o; } booloperator<=(Modint o) const { return v <= o.v; } booloperator>=(longlong o) const { return v >= o; } booloperator>=(Modint o) const { return v >= o.v; }