Teacher P buys a pencil

Teacher P buys a pencil

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 33 types of pencils in the store. The number of pencils in different packages may be different, and the price may 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 would cost to buy at least n pencils if 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.

Output format

1 integer, representing the least money that Teacher P needs to spend.

Input and output sample
input

57
2 2
50 30
30 27
output
54

Instructions/
Tips‍‍The three types of pencil packages are:
2 packs, the price is 2;
50 packs, the price is 30;
30 packs, the price is 27.
Teacher P needs to buy at least 57 pencils.
‍‍If she chooses to buy the first type of packaging, then she needs to buy 29 copies, a total of 58 pieces, and the cost is 58.
In fact, Teacher P will choose to buy the third package, so you need to buy 22 copies. Although the number of pencils I bought was more at 60, the cost was reduced to 54, which was less than the first one.

For the second type of packaging, although the price of each pencil is the lowest, you must buy 22 copies if you want to distribute it. The actual cost has reached 60, so Teacher P would not choose.
So the final output answer is 54.

Source code:

#include<stdio.h>
int main()
{
    
    
int a,n,n1,n2,x;
int b,b1,b2,c,c1,c2;
scanf("%d",&a);//a为需要购买数量
scanf("%d %d",&b, &c);//b为数量,c为购买价格
scanf("%d %d",&b1, &c1);
scanf("%d %d",&b2, &c2);
n=a/b;b=a%b==0?n:n+1;n=b*c;
n1=a/b1;b1=a%b1==0?n1:n1+1;n1=b1*c1;
n2=a/b2;b2=a%b2==0?n2:n2+1;n2=b2*c2;
if(n<n1&&n<n2)
{
    
    x=n;}
if(n1<n2&&n1<n)
{
    
    x=n1;}
if(n2<n1&&n2<n)
{
    
    x=n2;}
printf("%d",x);
return 0;
}

For C, let us work hard together.
Like follow

Guess you like

Origin blog.csdn.net/m0_46259251/article/details/105873743