N, K = map(int, input().split())arr = list(map(int, input().split()))arr.sort()sum_k = sum(arr[:K])print(*arr, sum_k)
8 3 10 20 30 45 31 42 12 16
10 12 16 20 30 31 42 45 38
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!