#P1336. 最佳课题选择
最佳课题选择
Description
Matrix67 must submit papers to his teacher next month. The content of each paper can be chosen from topics. Since the number of topics is limited, Matrix67 has to reuse some topics. The time required to complete papers on different topics varies. Specifically, for topic , if Matrix67 plans to write a total of papers, then the total time needed for that topic is time units. Given and for each topic, please help Matrix67 determine how to choose the topics for the papers so that the total time is minimized.
Input Format
The first line contains two integers and , representing the number of papers to complete and the number of available topics, respectively.
The next lines each contain two integers. On the -th line, the two numbers represent the time coefficient and the exponent corresponding to topic .
Output Format
Output the minimum total time required to complete papers.
10 3
2 1
1 2
2 1
19
Hint
Sample Explanation:
Choose topic 1 for papers, topic 3 for papers, and topic 2 for the remaining paper. The total time is . It can be proven that there is no better plan with total time less than .
Constraints:
For of the testdata, , .
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号