missing_coin_sum.cpp (641B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 using ui = unsigned int; 6 using l = long; 7 using ul = unsigned long; 8 using ll = long long; 9 using ull = unsigned long long; 10 11 using vi = vector<int>; 12 using vui = vector<ui>; 13 using vl = vector<l>; 14 using vul = vector<ul>; 15 using vll = vector<ll>; 16 using vull = vector<ull>; 17 18 void solve() 19 { 20 int n; 21 cin >> n; 22 int x[n]; 23 for (int i = 0; i < n; i++) 24 cin >> x[i]; 25 sort(x, x+n); 26 27 long res = 1; 28 int i = 0; 29 for (i = 0; i < n; i++) { 30 if (x[i] > res) { 31 cout << res << "\n"; 32 return; 33 } 34 res += x[i]; 35 } 36 cout << res << "\n"; 37 38 } 39 40 int main() 41 { 42 ios::sync_with_stdio(0); 43 cin.tie(0); 44 solve(); 45 }