SDAU课程练习1015

Problem Description

The cows have purchased a yogurt factory that makes world-famousYucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, theprice of milk and labor will fluctuate weekly such that it willcost the company C_i (1 <= C_i <= 5,000) cents to produce oneunit of yogurt in week i. Yucky's factory, being well-designed, canproduce arbitrarily many units of yogurt each week.

Yucky Yogurt owns a warehouse that can store unused yogurt at aconstant fee of S (1 <= S <= 100) cents per unit of yogurtper week. Fortuitously, yogurt does not spoil. Yucky Yogurt'swarehouse is enormous, so it can hold arbitrarily many units ofyogurt.

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 isthe delivery quantity in week i). Help Yucky minimize its costsover the entire N-week period. Yogurt produced in week i, as wellas any yogurt already in storage, can be used to meet Yucky'sdemand 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_iand Y_i.

 

Output

* Line 1: Line 1 contains a single integer: the minimum totalcost to satisfy the yogurt schedule. Note that the total might betoo large for a 32-bit integer.

 

Sample Input

4 5

88 200

89 400

97 300

91 500

 

Sample Output

126900

题目大意:

输入数据包含每天生产酸奶的价格和需要的数量,当天的需求可以当天生产,也可以用之前剩下的,每保存一天酸奶,每单位话费 样例中的 5。求最小花费。

思路:

每次生产时比较当天的价格和之前的价格(加上保存到现在的花费),取小的就行啦。

感想:

大半夜写的,困死了。。

AC代码:


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int a[10005];
int y[10005];
int main()
{
   //freopen("r.txt", "r", stdin);
    long longsum=0;
    intday,s,i;
   cin>>day>>s;
   for(i=1;i<=day;i++)
    {
       cin>>a[i];
       cin>>y[i];
       if(i==1)
       {
           sum+=a[i]*y[i];
           continue;
       }
       if(a[i-1]+s
           sum+=(a[i-1]+s)*y[i];
       else
       {
           sum+=a[i]*y[i];
       }
    }
   cout<<sum<<endl;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值