#include #include #include #include void solve() { int n, k; std::cin >> n >> k; std::vector xs(n); for (auto& x : xs) { std::cin >> x; x = std::max(x, 0); } std::sort(xs.rbegin(), xs.rend()); std::cout << std::accumulate(xs.begin(), xs.begin() + k, 0) << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }