Description
A communication company proposed a preferential SMS package policy to promote SMS.
You must select only one SMS package. Each package is in the form of p RMB per month. You can send F free text messages. If more than F items are exceeded, the excess part will be charged per a dollar.
Now you know that you need to send M text messages next month. Now there are too many types of text message packages in this company.ProgramTell him how much he needs to pay for the most economical text message package.
Input
Multiple groups of data are input. The first act integer N and m in each group of data are separated by a space, which is the number of types of packages and the number of text messages next month. 1 <= n <= 1000,0 <= m <= 10000
The next row has a real number A, indicating that the excess is charged for each a dollar. (0 <A <= 2)
In the following n rows, each line contains a real number P and an integer F, which are separated by a space, indicating that the SMS package is P yuan and can send F text messages. (0 <= P <= 100, 1 <= F <= 10000)
The input data ends with 0.
Output
Input data to each group and output the cost of using the most cost-effective SMS package. The second digit after the decimal point is retained.
Sample input 222
0.1
10 120
15 200
20 300
30 500
50 1000
2 451
0.2
55.50 800
33.30 400
0 0 example output 17.20
43.50
Solution:
It is also a simple simulation question. Calculate the total cost of each package and find the minimum value.
# Include <stdio. h> main () {int number, Tiao; int I, j; double result; double price; Double A [1001]; int B [1001]; double C [1001]; int K; double Max; scanf ("% d", & number, & Tiao); While (! (Number = 0 & Tiao = 0) {scanf ("% lf", & price); for (I = 0; I <number; I ++) scanf ("% lf % d", & A [I], & B [I]); For (k = 0, I = 0; I <number; I ++, k ++) {If (Tiao <B [I]) C [k] = A [I]; elsec [k] = (Tiao-B [I]) * Price + A [I];} max = C [0]; for (I = 0; I <number; I ++) {If (max> C [I]) max = C [I];} printf ("%. 2lf \ n ", max); scanf (" % d ", & number, & Tiao );}}