Christmas shopping
Practice
4.3 (3 votes)
Algorithms
Easy Medium
Sorting
Problem
68% Success 1890 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

x-mas tree

The Lalalandia's Christmas is coming! Only N days are left and Jambo wants to buy all his friends a present. There are N presents that his friends want and Jambo, because he is a very small elephant, cannot buy and carry more than K presents at any day. Every present in jth day costs \(a_i * j\) for every \(1 \le j \le N\). Can you help Jambo determine the minimum amount of money needed to buy all presents and make his friends happy?

Input format

The first line consists of integers N - the number of days and the number of presents Jambo wants to buy, and K - the number of presents Jambo can carry. The second line contains n integers \(a_1, a_2, ..., a_N\) — the cost of the ith present.

Output format

The first line should contain the single integer - answer to the problem.

Constraints:

\(1 \le N \le 10^5\)

\(1 \le K \le N\)

\(1 \le a_i \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
11 votes
Tags:
SortingAlgorithmsEasy-MediumSorting
Points:30
4 votes
Tags:
Ad-HocRecursionSortingEasy-Medium
Points:30
2 votes
Tags:
SortingStringsEasy-Medium