Santa and Letters

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type

A big part of Santa's day-to-day life is answering letters from children. However, some of these letters are too long and Santa wastes a lot of time reading them. Your next task is to solve this problem for him.

Efficient as always, you hire an elf assistant to screen all of the N letters that are currently in Santa's mailbox. The assistant will give the ith letter a positive integer score t_i, denoting the amount of time it would take for Santa to read the letter.

After the letters are screened, you decide to only give Santa the K shortest letters to read. You must report the total time that Santa will spend reading the letters.

Input Specification

The first line will contain two space-separated integers, N and K (1 \le K \le N \le 10^5).

The next line will contain N space-separated integers, t_1, t_2, ..., t_N (1 \le t_i \le 10^3).

Output Specification

Output one line containing the total time that Santa spends reading the letters if he is given the K shortest letters.

Sample Input

5 3
1 4 3 10 2

Sample Output



There are no comments at the moment.