fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int n;
  8. cin>>n;
  9.  
  10. int a[n];
  11. for(int i=0;i<n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15.  
  16. sort(a,a+n);
  17.  
  18. long long target=1;
  19. for(int i=0;i<n;i++)
  20. {
  21. if(a[i] > target)
  22. {
  23. break;
  24. }
  25.  
  26. target+=a[i];
  27. }
  28.  
  29. cout<<target<<endl;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
2 9 1 2 7
stdout
6