fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdexcept>
  4. #include <algorithm>
  5. #include <functional>
  6.  
  7. int func(std::vector<int> v)
  8. {
  9. if(v.size() < 3) throw std::runtime_error("Your vector is too small");
  10. nth_element(v.begin(), v.begin()+3, v.end(), std::greater<int>());
  11. return v[0] + v[1] + v[2];
  12. }
  13. int main()
  14. {
  15. std::cout << func({1,2,3,4,5,6,7,8,9,10,20,30}) << '\n';
  16. }
  17.  
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
60