Description
The cows have purchased a yogurt factory that makes world-famous yucky yogurt. over the next N (1 <= n <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_ I (1 <= C_ I <= 5,000) cents to produce one unit of yogurt in week I. yucky's factory, being well-designed, can produce arbitrarily extends units of yogurt each week.
Yucky yogurt owns a warehouse that can store unused yogurt at a constant ratio of S (1 <= S <= 100) cents per unit of yogurt per week. fortuitously, yogurt does not spoil. yucky yogurt's warehouse is enormous, so it can hold arbitrarily quota units of yogurt.
Yucky wants to find a way to make weekly deliveries of y_ I (0 <= y_ I <= 10,000) units of yogurt to its clientele (y_ I is the delivery quantity in week I ). help yucky minimize its costs over the entire N-week period. yogurt produced in week I, as well as any yogurt already in storage, can be used to meet yucky's demand for that week.
Input
* Line 1: two space-separated integers, N and S.
* Lines 2. n + 1: line I + 1 contains two space-separated integers: C_ I and y_ I.
Output
* Line 1: Line 1 contains a single INTEGER: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.
Sample Input
4 588 20089 40097 30091 500
Sample output
126900
Hint
Output details:
In week 1, produce 200 units of yogurt and deliver all of it. in week 2, produce 700 units: deliver 400 units while storing 300 units. in week 3, deliver the 300 units that were stored. in Week 4, producer and deliver 500 units. the cost of producing cheese in a factory is different every week. If the hourly cost of producing cheese reaches the expected value, the store will be charged per week. How can the production cost be the lowest and the lowest output cost. Idea: DP; Specific: Compare the weekly cost with the lowest storage cost in the previous weeks. AC code:
#include<stdio.h>#include<string.h>int min(int a,int b){ if(a>b) return b; else return a;}int main(){ int a,b,i,j,n,x[100000],y[100000]; while(scanf("%d%d",&a,&b)!=EOF) { long long sum=0; for(i=1;i<=a;i++) scanf("%d%d",&x[i],&y[i]); for(i=2;i<=a;i++) x[i]=min(x[i],x[i-1]+b); for(i=1;i<=a;i++) sum+=x[i]*y[i]; printf("%lld\n",sum); }}
If you have any questions, please comment on them.