CF 839A - Arya and Bran
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
-----------------------------------------------------------------------------
布蘭和他的姐姐艾莉亞來(lái)自同一所房子。 布蘭非常喜歡糖果,所以艾莉亞要給他一些糖果。
起初,艾莉亞和布蘭有 0 顆糖果。 有n天了,在第i天,艾莉亞在盒子里發(fā)現(xiàn)了千面之神賜予的糖果。 她每天最多可以給布蘭 8 顆糖果。 如果她當(dāng)天沒(méi)有給他糖果,這些糖果就會(huì)為她保留,她可以稍后再給他。
你的任務(wù)是找出在第 n 天結(jié)束之前艾莉亞需要給布蘭克糖果的最少天數(shù)。 形式上,您需要輸出將發(fā)出 k 顆糖果的最小天數(shù)索引(天數(shù)索引從 1 到 n)。
如果她在給定的 n 天內(nèi)無(wú)法給他 k 顆糖果,則輸出 -1。
-------------------------------------------------------
用兩個(gè)半兩一次存儲(chǔ)每次可以給出的糖果,以及每次自己還剩下的糖果,依次遍歷即可;