commit e403ee5e221be27a14411d0b92529053c5ac7a8d parent d0027d121b9d298387d77bada117bac7caa3726f Author: superpozycja <anna@superpozycja.net> Date: Tue, 29 Oct 2024 11:08:57 +0100 solve missing coin sum Diffstat:
A | sorting_and_searching/missing_coin_sum.cpp | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 45 insertions(+), 0 deletions(-)
diff --git a/sorting_and_searching/missing_coin_sum.cpp b/sorting_and_searching/missing_coin_sum.cpp @@ -0,0 +1,45 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n; + cin >> n; + int x[n]; + for (int i = 0; i < n; i++) + cin >> x[i]; + sort(x, x+n); + + long res = 1; + int i = 0; + for (i = 0; i < n; i++) { + if (x[i] > res) { + cout << res << "\n"; + return; + } + res += x[i]; + } + cout << res << "\n"; + +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}