zoukankan      html  css  js  c++  java
  • codeforce 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.

    Input

    The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).

    The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).

    Output

    If it is impossible for Arya to give Bran k candies within n days, print -1.

    Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.

    Examples
    Input
    2 3
    1 2
    Output
    2
    Input
    3 17
    10 10 10
    Output
    3
    Input
    1 9
    10
    Output
    -1
    Note

    In the first sample, Arya can give Bran 3 candies in 2 days.

    In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.

    In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 using namespace std;
     5 
     6 
     7 int main()
     8 {
     9     int n,k;
    10     scanf("%d%d",&n,&k);
    11     int a[105],tmpk=0,i;
    12     bool flag=false;
    13     for(i=0;i<n;i++)
    14     {
    15         scanf("%d",&a[i]);
    16     }
    17     for(i=0;i<n;i++)
    18     {
    19         if(a[i]>=8)
    20         {
    21             tmpk+=8;
    22             a[i]-=8;
    23             a[i+1]+=a[i];
    24         }
    25         else
    26         {
    27             tmpk+=a[i];
    28         }
    29         if(tmpk>=k)
    30         {
    31             flag=true;
    32             break;
    33         }
    34     }
    35     if(flag)
    36         printf("%d
    ",i+1);
    37     else
    38         printf("-1
    ");
    39     return 0;
    40 }
  • 相关阅读:
    android问题及其解决-优化listView卡顿和怎样禁用ListView的fling
    平安科技移动开发二队技术周报(第三期)
    机房重构(个人版)——类图
    php-wamp环境搭建
    ajax 通过return 返回data值
    cocos2d-x中六种持续性动作
    Android SimpleAdapter
    jquery 判断当前上传文件大小限制上传格式 搭配thinkphp实现上传即预览(模拟异步上传)
    【转】我的第一个Python小程序
    python官网
  • 原文地址:https://www.cnblogs.com/Annetree/p/7368360.html
Copyright © 2011-2022 走看看