#P1070C. Cloud Computing
Cloud Computing
No submission language available for this problem.
Description
Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for consecutive days, which are numbered from to . Buber requires CPU cores each day.
The cloud provider offers tariff plans, the -th tariff plan is characterized by the following parameters:
- and — the -th tariff plan is available only on days from to , inclusive,
- — the number of cores per day available for rent on the -th tariff plan,
- — the price of renting one core per day on the -th tariff plan.
Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to ) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.
Find the minimum amount of money that Buber will pay for its work for days from to . If on a day the total number of cores for all available tariff plans is strictly less than , then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly cores this day.
The first line of the input contains three integers , and () — the number of days to analyze, the desired daily number of cores, the number of tariff plans.
The following lines contain descriptions of tariff plans, one description per line. Each line contains four integers , , , (, ), where and are starting and finishing days of the -th tariff plan, — number of cores, — price of a single core for daily rent on the -th tariff plan.
Print a single integer number — the minimal amount of money that Buber will pay.
Input
The first line of the input contains three integers , and () — the number of days to analyze, the desired daily number of cores, the number of tariff plans.
The following lines contain descriptions of tariff plans, one description per line. Each line contains four integers , , , (, ), where and are starting and finishing days of the -th tariff plan, — number of cores, — price of a single core for daily rent on the -th tariff plan.
Output
Print a single integer number — the minimal amount of money that Buber will pay.