Yachts

Description

Everybody knows that the Yekaterinozavodsk Shipyard constructs the best yachts in the world. They are so popular
 that when a manufacturer becomes a billionaire, he comes to the shipyard in the end of the same month to get a new
 yacht. You bet! The yachts are hand-made and their interior is made from a valuable red-black tree. Unfortunately, 
there are few workers at the shipyard, therefore, it can build no more than  d new yachts per month. As a result, the
shipyard sometimes cannot produce enough yachts for their customers. And those billionaires are quite impulsive 
people: if they come to the shipyard and there is no yacht for them, they abandon the whole idea of buying a yacht. 
Of course, the shipyard can produce yachts and store them somewhere for future use, but you should pay 1 golden 
bar to store one yacht during one month.The managers want to know the maximal number of yachts the shipyard can 
sell during the next  n months, and the miminal number of golden bars which should be paid for the storage. The students 
from the Department of Economics of the Yekaterinozavodsk University predicted the amount of future billionaires in
 each of these  n months. You should use this data to answer the managers' questions.

Input

The first line contain space-separated integers  n and  d ( 1 ≤  n ≤ 20000 ;  1 ≤  d ≤ 100000 ). The second line contains 
space-separated integers  a 1a 2, …,  anai is the number of future billionaires in  i-th month  (0 ≤  ai ≤ 100000) .

Output

Output two integers separated by space — the maximal number of yachts the shipyard can sell and the minimal 
number of golden bars required to pay for the storage.

Sample Input

input output
3 5
6 1 7
13 2

题目大意一时半会说不清楚!!

以样例解释,3表示有三个月,即第二行的数据个数。5表示没个月生产船的最大量,每月最多不能超过这个数。下面几个数就带表客户需要的量,如果客户多了,客户便自动回去,退出!而公司生产的如果要放在仓库,则每个月要消费1;输出最多生产量和消费量!!具体题目自己看看吧!!

此题要用一定的技巧!!

用数组存好之后,从后向前遍历一次求出最大生产量。再从前向后遍历一下就能得出消费量。

总之,把一个数组,向前遍历和向后遍历!!

本人个人认为 int 就可以搞定,可是一直过不了,如有大牛,求指点!!

代码如下:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
int main()
{
    __int64 n,m;
    __int64 a[20005];
    __int64 b[20005];
    __int64 c[20005];
    while(~scanf("%I64d%I64d",&n,&m))
    {
        __int64 sum=0;
        __int64 kk=0;
        for(int i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            c[i]=a[i];
        }
        for(int j=n-1; j>=0; j--)
        {
            if(a[j]>m)
            {
                b[j]=m;
                a[j-1]=a[j-1]+a[j]-m;
            }
            else
                b[j]=a[j];
            sum+=b[j];
        }
        __int64 s=0;
        for(int k=0; k<n; k++)
        {
            if(c[k]<=b[k])
            {
                kk=b[k]-c[k];
                b[k+1]=kk+b[k+1];
                s+=kk;
            }
            else
                kk=0;
        }
        printf("%I64d %I64d\n",sum,s);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值