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 = A[0] for i := 1; i < K; i++ { if A[i] <= 0 { break } sum += A[i] } fmt.Println(sum) }