#include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ int n, k, sum1 = 0; cin >> n >> k; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end(), greater()); for (int i = 0; i < k; i++){ if(a[i] > 0) sum1 += a[i]; else break; } cout << sum1 << endl; }