Codeforces Round #355 (Div. 2) B. Vanya and Food Processor

时间:2023-03-10 03:42:50
Codeforces Round #355 (Div. 2) B. Vanya and Food Processor

菜菜菜!!!这么撒比的模拟题,听厂长在一边比比比了半天,自己想一想,然后纯模拟一下,中间过程检测一下,妥妥的就可以过。

题意:有N个东西要去搞碎,每个东西有一个高度,然后有一台机器支持里面可以达到的最大高度,东西可以连续放进去,只要不超过h就行了,每秒可以搞k高度,然后让你算时间

直接code:

#include<cstdio>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0X3f3f3f3f
#define N 100010
typedef long long LL; LL a[N];
LL b[N]; bool cmp(LL n,LL m)
{
return n>m;
} int main()
{
LL n,k,h;
cin>>n>>h>>k;
for(int i=0; i<n; i++)
{
scanf("%I64d",&a[i]);
}
LL ans=0;
LL nowh=0;
int i=0; for(int i=0;i<n;i++)
{
if(nowh+a[i]<=h)
{
nowh+=a[i];
}
else
{
ans+=nowh/k;
if(nowh%k)
ans++;
nowh=0;
i--;
}
if(nowh>=k)
{
ans+=nowh/k;
nowh%=k;
}
// printf("nowh=%d\n",nowh);
// printf("ans =%d\n",ans);
}
if(nowh)
{
ans+=nowh/k;
if(nowh)
ans++;
}
printf("%I64d\n",ans);
return 0;
}