#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';
}
