AmazonOA #254
Make Array Distinct (Selling Shoes )
Estimated HardJudge-ready
Topics (AI-labelled)Stacks & HeapsGreedy
Each product's size can only increase, and each unit of increase costs that product's cost. All final sizes must be distinct; find the minimum total cost. Every product is kept, and there is no upper limit on the final sizes.
Input
The first line contains n, the second line size, and the third line cost. This page gives no numeric bounds, but the original text explicitly links to the same problem amazon-get-minimal-cost.md, whose full bounds are added here: 1≤n≤200000, 1≤size≤10^9, 1≤cost≤10000.
Output
Output a single integer, the answer.
Example 1
Input:
2
1 1
1 2
Output:
1
Example 2
Input:
4
2 3 3 2
2 4 5 1
Output:
7
Example 3
Input:
2
1 10
10000 1
Output:
0
Example notes
The answers are 1, 7 and 0. Every unit is charged; you cannot just take the total cost minus the cost of each item as it leaves the heap.
Editorial
Loading solution…