cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

missing_coin_sum_2183.cpp (301B)


      1 #include <algorithm>
      2 #include <iostream>
      3 #include <vector>
      4 
      5 int main() {
      6 	size_t n, s{1};
      7 	std::cin >> n;
      8 	std::vector<size_t> a(n);
      9 	for (size_t i = 0; i < n; i++)
     10 		std::cin >> a[i];
     11 	std::sort(a.begin(), a.end());
     12 	for (auto c : a)
     13 		if (s < c) break;
     14 		else s+= c;
     15 	std::cout << s << std::endl;
     16 }