CUC-SUMMER-6-F

F - Vanya and Food Processor
CodeForces - 677B

Vanya smashes potato in a vertical food processor. At each moment of time the height of the potato in the processor doesn't exceed h and the processor smashes k centimeters of potato each second. If there are less than k centimeters remaining, than during this second processor smashes all the remaining potato.

Vanya has n pieces of potato, the height of the i-th piece is equal to ai. He puts them in the food processor one by one starting from the piece number 1 and finishing with piece number n. Formally, each second the following happens:

If there is at least one piece of potato remaining, Vanya puts them in the processor one by one, until there is not enough space for the next piece.
Processor smashes k centimeters of potato (or just everything that is inside).
Provided the information about the parameter of the food processor and the size of each potato in a row, compute how long will it take for all the potato to become smashed.

Input
The first line of the input contains integers n, h and k (1?≤?n?≤?100?000,?1?≤?k?≤?h?≤?109) — the number of pieces of potato, the height of the food processor and the amount of potato being smashed each second, respectively.

The second line contains n integers ai (1?≤?ai?≤?h) — the heights of the pieces.

Output
Print a single integer — the number of seconds required to smash all the potatoes following the process described in the problem statement.

Example
Input
5 6 3
5 4 3 2 1
Output
5
Input
5 6 3
5 5 5 5 5
Output
10
Input
5 6 3
1 2 1 1 1
Output
2
Note
Consider the first sample.

First Vanya puts the piece of potato of height 5 into processor. At the end of the second there is only amount of height 2 remaining inside.
Now Vanya puts the piece of potato of height 4. At the end of the second there is amount of height 3 remaining.
Vanya puts the piece of height 3 inside and again there are only 3 centimeters remaining at the end of this second.
Vanya finally puts the pieces of height 2 and 1 inside. At the end of the second the height of potato in the processor is equal to 3.
During this second processor finally smashes all the remaining potato and the process finishes.
In the second sample, Vanya puts the piece of height 5 inside and waits for 2 seconds while it is completely smashed. Then he repeats the same process for 4 other pieces. The total time is equal to 2·5?=?10 seconds.

In the third sample, Vanya simply puts all the potato inside the processor and waits 2 seconds.


題意:機(jī)器有h的高度,每次處理k高度的土豆凭舶,如果不足k則全部處理蝶锋,如果放入土豆之后土豆高度不超過h則加入土豆砚偶,求多長(zhǎng)時(shí)間處理完

解法:直接模擬即可,注意要用longlong來存淋昭,處理時(shí)用除法不要用減法,否則時(shí)間會(huì)暴。

代碼:

#include<iostream>
using namespace std;
int main()
{
    int n,h,k,a,r=0,i,flag=1;
    long long ans=0;
    cin>>n>>h>>k;
    for(i=0;i<n;i++){
        cin>>a;
        if(r>=k){
            ans+=r/k;
            r%=k;
        }
        if(r+a>h){
            r=a;
            ans++;
        }
        else
            r+=a;
    }
    ans+=r/k;
    if(r%k!=0)
        ans++;
    cout<<ans<<endl;
    return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末型宙,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子伦吠,更是在濱河造成了極大的恐慌妆兑,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,378評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件毛仪,死亡現(xiàn)場(chǎng)離奇詭異搁嗓,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)箱靴,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,356評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門腺逛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人衡怀,你說我怎么就攤上這事棍矛。” “怎么了抛杨?”我有些...
    開封第一講書人閱讀 152,702評(píng)論 0 342
  • 文/不壞的土叔 我叫張陵够委,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我怖现,道長(zhǎng)茁帽,這世上最難降的妖魔是什么玉罐? 我笑而不...
    開封第一講書人閱讀 55,259評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮潘拨,結(jié)果婚禮上吊输,老公的妹妹穿的比我還像新娘。我一直安慰自己铁追,他們只是感情好季蚂,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,263評(píng)論 5 371
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著琅束,像睡著了一般扭屁。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上狰闪,一...
    開封第一講書人閱讀 49,036評(píng)論 1 285
  • 那天疯搅,我揣著相機(jī)與錄音,去河邊找鬼埋泵。 笑死幔欧,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的丽声。 我是一名探鬼主播礁蔗,決...
    沈念sama閱讀 38,349評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼雁社!你這毒婦竟也來了浴井?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,979評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤霉撵,失蹤者是張志新(化名)和其女友劉穎磺浙,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體徒坡,經(jīng)...
    沈念sama閱讀 43,469評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡撕氧,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,938評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了喇完。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片伦泥。...
    茶點(diǎn)故事閱讀 38,059評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖锦溪,靈堂內(nèi)的尸體忽然破棺而出不脯,到底是詐尸還是另有隱情,我是刑警寧澤刻诊,帶...
    沈念sama閱讀 33,703評(píng)論 4 323
  • 正文 年R本政府宣布防楷,位于F島的核電站,受9級(jí)特大地震影響坏逢,放射性物質(zhì)發(fā)生泄漏域帐。R本人自食惡果不足惜赘被,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,257評(píng)論 3 307
  • 文/蒙蒙 一是整、第九天 我趴在偏房一處隱蔽的房頂上張望肖揣。 院中可真熱鬧,春花似錦浮入、人聲如沸龙优。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,262評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽彤断。三九已至,卻和暖如春易迹,著一層夾襖步出監(jiān)牢的瞬間宰衙,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,485評(píng)論 1 262
  • 我被黑心中介騙來泰國(guó)打工睹欲, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留供炼,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,501評(píng)論 2 354
  • 正文 我出身青樓窘疮,卻偏偏與公主長(zhǎng)得像袋哼,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子闸衫,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,792評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,389評(píng)論 0 23
  • 無言的寂寞 是從胸口抽出來的絲 將我們包裹 卻又不讓我們觸摸 繚繞的惆悵 是夏荷揮灑的馨香 偶然間竄入鼻中 仔細(xì)嗅...
    那夜秋色閱讀 130評(píng)論 0 0
  • 寶寶這會(huì)已經(jīng)睡著了涛贯,看著他熟睡的面孔,我感覺特別的幸福蔚出。有這樣一個(gè)說法弟翘,每個(gè)寶寶在天上的時(shí)候就會(huì)選擇自己的媽媽,說...
    小魔女_fb70閱讀 190評(píng)論 0 0
  • 一骄酗、表示整十的基數(shù)詞用復(fù)數(shù)形式可以表示人的歲數(shù)或年代稀余。 如:in the sixties 在60年代in one’...
    春喜外語閱讀 1,418評(píng)論 0 0
  • 哇擦擦,居然有人喜歡用iPhone的粗體模式酥筝,設(shè)置方式為“設(shè)置-通用-輔助功能-Bold Text”滚躯,看起來好丑,...
    jy__Lu閱讀 1,337評(píng)論 0 0