Huawei OD Online OJ:
Users who have already purchased this column, please private message the blogger to open an account and brush up questions online! ! !
Online OJ: brush the questions immediately
Question bank column: 2023 Huawei OD machine test (A volume + B volume) (C++JavaJSPy)
topic description
There are m shops in a shopping mall, and now it is decided to hold an event to select the most popular shops.
A total of n citizens participated in the activity, and each citizen could only vote for one vote. However, if shop No. 1 gave the citizen a shopping subsidy of q yuan, the citizen would vote for shop No. 1 instead.
Please calculate the minimum amount of shopping subsidies that store 1 needs to issue to become the most popular store (that is, the number of votes obtained is greater than that of other stores). If store 1 itself is the store with the highest number of votes, return 0.
enter description
The first line is two integers n and m separated by lowercase commas, where:
- The first integer n represents the total number of citizens participating
- The second integer m represents the total number of stores
- 1 ≤ n,m ≤ 3000
Lines 2 to n+1, each line is two integers p, q separated by a lowercase comma, indicating the citizens’ intention to vote, where each line:
- The first integer p indicates that the citizen intends to vote for p shop
- The second integer q represents the shopping subsidy of q yuan required to switch to No. 1 store
- 1 ≤ p ≤ m
- 1 ≤ g ≤ 10^9
Regardless of the format of the input