atcoder#ABC188D. [ABC188D] Snuke Prime
[ABC188D] Snuke Prime
Score : points
Problem Statement
Snuke Inc. offers various kinds of services. A payment plan called Snuke Prime is available. In this plan, by paying yen (the currency of Japan) per day, you can use all services offered by the company without additional fees. You can start your subscription to this plan at the beginning of any day and cancel your subscription at the end of any day.
Takahashi is going to use of the services offered by the company. He will use the -th of those services from the beginning of the -th day until the end of the -th day, where today is the first day. Without a subscription to Snuke Prime, he has to pay yen per day to use the -th service.
Find the minimum total amount of money Takahashi has to pay to use the services.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum total amount of money Takahashi has to pay.
2 6
1 2 4
2 2 4
10
He will use the -st service on the -st and -nd days, and the -nd service on the -nd day. If he subscribes to Snuke Prime only on the -nd day, he will pay yen on the -st day and yen on the -nd day, for a total of yen. It is impossible to make the total payment less than yen, so we should print .
5 1000000000
583563238 820642330 44577
136809000 653199778 90962
54601291 785892285 50554
5797762 453599267 65697
468677897 916692569 87409
163089627821228
It is optimal to do without Snuke Prime.
5 100000
583563238 820642330 44577
136809000 653199778 90962
54601291 785892285 50554
5797762 453599267 65697
468677897 916692569 87409
88206004785464