package main import ( "fmt" "sort" ) func main() { var N, K int fmt.Scan(&N, &K) A := make([]int, N) for i := 0; i < N; i++ { fmt.Scan(&A[i]) } sort.Sort(sort.Reverse(sort.IntSlice(A))) var sum int for i := 0; i < K; i++ { if A[i] <= 0 { break } sum += A[i] } fmt.Println(sum) }