fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. long long t = 1, n = 0, q = 0, m = 0, num = 0;
  7.  
  8. cin>>n;
  9.  
  10. while(n){
  11.  
  12. vector <long long> v, aux;
  13.  
  14. n--;
  15. cin>>m;
  16. while(m--){
  17. cin>>num;
  18. v.push_back(num);
  19. }
  20.  
  21. sort(v.begin(), v.end());
  22.  
  23. aux.push_back(v.front());
  24. t = aux.front();
  25. for(int i = 1; i < v.size(); i++){
  26. aux.push_back(aux[i-1] + v[i]);
  27. if(t >= v[i-1] && t <= aux[i-1]){
  28. t = aux[i]+1;
  29. }
  30. }
  31.  
  32. cout<<t<<endl;
  33.  
  34.  
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 15240KB
stdin
3
1
1
1
2
3
2 1 5
stdout
1
2
4