Shopping (Contest)
Shopping easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Shopping easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Toros went to the supermarket to buy K items. There were a total of N items. Each item had a distinct price Pi. He is cost-effective, so he would buy the K cheapest item. But he knows that the more cheaper an item is, the more is the chances that it can be defective. So he planned to ignore 2 cheapest items and buy K from the remaining ones. Find the total cost of all items that he would buy. Input The first line contains two integers N and K, denoting the total number of items in the supermarket and the number of items Toros is going to buy. The second line contains N distinct integers Pi , denoting the prices of the items
Constraints: 1 <= N <= 100000 1 <= K <= N - 2 1 <= Pi <= 1000000 Output Print a single integer denoting the total cost of items Toros would buy. Example Sample Input: 5 2 4 1 2 3 5
Sample Output: 7
Explanation: Toros will ignore items with price 1 and 2 and would buy items with price 4 and 3.
Sample Input: 10 8 99 56 50 93 47 36 65 25 87 16
Sample Output: 533
link: