2017 ACM-ICPC 亚洲区-Coconut


Discussion

Coconut is Captain Gangplank’s favourite fruit. That is why he needs to drink coconut 
juice from b coconuts each day. 
On his next trip, he would pass through N citis. 
His trip would begin in the 1-st city and end in the N-th city. 
The journey from the i-th city to the (i + 1)-th city costs D days. 
Initially, there is no coconut on his ship. Fortunately, he could get supply of C coconuts 
from the i-th city. 
Could you tell him, whether he could drink coconut juice every day during the trip no 
not? 

Input Format

The first line contains an integer T, indicating that there are T test cases. 
For each test case the first line contains two integers N and b as described above. 
The second line contains N integers C , C ,⋯, C . 
The third line contains N − 1 integers D , D ,⋯, D . 
All integers in the input are less than 1000.

Output Format

For each case, output Yes if Captain Gangplank could drink coconut juice every day, 
and otherwise output No.

Sample Input


4 1 
3 2 1 4 
1 2 3 
4 2 
2 4 6 8 
3 2 1

Sample Output

Yes 
No

题意:

船长将要旅行N个城市,从i到第i+1个城市需要Di天,路过的第i个城市受供Ci个椰子,每天需要吃b个椰子,问船长是否每天都能吃到椰子。

思路:

根据题意,简单模拟。

code:

#include <iostream>
#include <algorithm>
#include <cstdio>

int cd[2][1005];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,b,sum=0;
        scanf("%d%d",&n,&b);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&cd[0][i]);
        }
        for(int i=0;i<n-1;i++)
        {
            scanf("%d",&cd[1][i]);
        }
        cd[1][n-1]=0;
        int i;
        for(i=0;i<n;i++)//cities
        {
            sum+=cd[0][i];
            sum-=b*cd[1][i];
            if(sum<0)
            {
                break;
            }
        }
        if(i==n)
            printf("Yes\n");
        else
            printf("No\n");
    }
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值