Title description
Teacher P needs to go to the store to buy n pencils as gifts for children to participate in NOIP. She found that there are 3 types of pencils in the store. The number of pencils in different packages may be different, and the price may also be different. To be fair, Teacher P decided to buy only pencils in the same packaging.
The store does not allow unpacking the pencils, so Teacher P may need to buy more than n pencils to give gifts to children.
Now Teacher P wants to know how much it will cost at least to buy at least n pencils when the quantity of each package in the store is sufficient.
Input format The
first line contains a positive integer n, indicating the number of pencils needed.
In the next three lines, each line uses 2 positive integers to describe a package of pencils: the first integer represents the number of pencils in this package, and the second integer represents the price of this package.
Ensure that all 7 numbers are positive integers not exceeding 10,000.
The output format is
1 integer, which represents the least money that Teacher P needs to spend.
Input and output sample
input #1
57
2 2
50 30
30 27
output #1
54
input #2
9998
128 233
128 2333
128 666
output #2
18407
input #3
9999
101 1111
1 9999
1111 9999
output #3
89991
code:
//P1909 买铅笔
#include<iostream>
#include<algorithm>
using namespace std;
int num[3], p[3], s[3], n;
int main()
{
cin >> n;
for(int i = 0; i < 3; i++)
cin >> num[i] >> p[i];
for(int i = 0; i < 3; i++)
if(n % num[i] == 0) s[i] = n / num[i] * p[i];
else s[i] = (n / num[i] + 1) * p[i];
sort(s, s + 3);
cout << s[0] << endl;
return 0;
}