CF893D.Credit Card

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Recenlty Luba got a credit card and started to use it. Let's consider nn consecutive days Luba uses the card.

She starts with 00 money on her account.

In the evening of ii -th day a transaction aia_{i} occurs. If a_{i}>0 , then aia_{i} bourles are deposited to Luba's account. If a_{i}<0 , then aia_{i} bourles are withdrawn. And if ai=0a_{i}=0 , then the amount of money on Luba's account is checked.

In the morning of any of nn days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed dd .

It can happen that the amount of money goes greater than dd by some transaction in the evening. In this case answer will be «-1».

Luba must not exceed this limit, and also she wants that every day her account is checked (the days when ai=0a_{i}=0 ) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her!

输入格式

The first line contains two integers nn , dd ( 1<=n<=1051<=n<=10^{5} , 1<=d<=1091<=d<=10^{9} ) —the number of days and the money limitation.

The second line contains nn integer numbers a1,a2,... ana_{1},a_{2},...\ a_{n} ( 104<=ai<=104-10^{4}<=a_{i}<=10^{4} ), where aia_{i} represents the transaction in ii -th day.

输出格式

Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money.

输入输出样例

  • 输入#1

    5 10
    -1 5 0 -5 3
    

    输出#1

    0
    
  • 输入#2

    3 4
    -10 0 20
    

    输出#2

    -1
    
  • 输入#3

    5 10
    -5 0 10 -11 0
    

    输出#3

    2
    
首页