2017 ACM-ICPC 亚洲区-Coconut

àì夳堔傛蜴生んèń 2022-06-08 02:07 275阅读 0赞

#

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

2
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:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. int cd[2][1005];
  5. int main()
  6. {
  7. int t;
  8. scanf("%d",&t);
  9. while(t--)
  10. {
  11. int n,b,sum=0;
  12. scanf("%d%d",&n,&b);
  13. for(int i=0;i<n;i++)
  14. {
  15. scanf("%d",&cd[0][i]);
  16. }
  17. for(int i=0;i<n-1;i++)
  18. {
  19. scanf("%d",&cd[1][i]);
  20. }
  21. cd[1][n-1]=0;
  22. int i;
  23. for(i=0;i<n;i++)//cities
  24. {
  25. sum+=cd[0][i];
  26. sum-=b*cd[1][i];
  27. if(sum<0)
  28. {
  29. break;
  30. }
  31. }
  32. if(i==n)
  33. printf("Yes\n");
  34. else
  35. printf("No\n");
  36. }
  37. }

发表评论

表情:
评论列表 (有 0 条评论,275人围观)

还没有评论,来说两句吧...

相关阅读