#include using namespace std; int main() { int n, k; vector a; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; a.push_back(x); } sort(a.begin(), a.end()); int ans = 0; if (k > a.size()) { k = a.size(); } for (int i = 0; i < k; i++) { if (a.back() > 0) { ans += a.back(); a.pop_back(); } } cout << ans << "\n"; }