AmazonOA #372
Get Minimum Cost
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsGreedy
In category i, the j-th item costs a[i]+(j−1)b[i], and every category has infinitely many items. Buy exactly m items and minimize the total price.
Input
The first line contains n m, followed by one line of n values a and one line of n values b. The original bounds are 1≤n,m≤100000, 1≤a[i],b[i]≤100000.
Output
Output a single integer, the answer.
Example 1
Input:
3 4
2 1 1
1 2 3
Output:
7
Example 2
Input:
1 3
5
2
Output:
21
Example 3
Input:
2 3
1 2
100 1
Output:
6
Example notes
The outputs of the three public examples are 7; 21; and 6, checked by independent enumeration or direct simulation.
Editorial
Loading solution…