language: C++11 (gcc-4.7.2)
date: 173 days 23 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <vector>
#include <stdexcept>
#include <algorithm>
#include <functional>
 
int func(std::vector<int> v)
{
    if(v.size() < 3) throw std::runtime_error("Your vector is too small");
    nth_element(v.begin(), v.begin()+3, v.end(), std::greater<int>());
    return  v[0] + v[1] + v[2];
}
int main()
{
    std::cout << func({1,2,3,4,5,6,7,8,9,10,20,30}) << '\n';
}