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