Math, asked by miracle7781, 1 year ago

Chappu is addicted to paneer! Nikau wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly a[i] kilograms of paneer. There is a big shop uptown and nikau wants to buy paneer for her from there. In i-th day, they sell paneer for pi dollars per kilogram. Nikau knows all numbers a1,...,an and p1,...,pn. In each day, he can buy arbitrary amount of paneer, also he can keep some paneer he has for the future. Nikau is a little tired from cooking paneer, so he asked for your help. Help him to minimize the total money he spends to keep chappu happy for n days.

Answers

Answered by Agastya0606
2

Given: Days = n, nikau knows all numbers a1,...,an and p1,...,pn and in each day, he can buy arbitrary amount of paneer.

To find:  To minimize the total money he spends?

Solution:

  • So now the solution is in the form of programming.
  • Let the first line of in put be n, so, it will print the minimum money needed for n days in order to keep chappu happy.
  • Let ai and pi be two integers, for the amount of paneer.

               (1<=z[x] )

So, according to question, code goes like this:

include<conio.h>

include<stdio.h>

int main()

{

int n;                            #declaring n for days

scanf("%d",&n);

int z[n][2], x=0, answer=0;

   for( x = 0; x < n ; x++ )

   {

    scanf( "%d %d", &z[x][0], &z[x][1] );

   }

   answer = answer + z[0][0] x z[0][1] ;

   for( x = 1 ; x < n ; x++ )

   {

       if ( z[x][1] > z[x-1][1] )

           z[x][1] = z[x-1][1] ;

   

   }

   for(x=1 ; x < n ; x++ )

       answer = answer + z[i][0]*z[i][1];

   

   printf("%d", answer );

   return 0;

}

So this can be the following code .

Answer:

            So the following code can help him to minimize the total money he spends to keep chappu happy for n days.

Similar questions