After the data structures exam, students lined up in the cafeteria to have a drink and chat about how much they have enjoyed the exam and how good their professors are. Since it was late in the evening, the cashier has already closed the cash register and does not have any change with him.

The students are going to pay using Jordanian money notes, which are of the following types: 1, 5, 10, 20, 50.

Given how much each student has to pay, the set of notes he’s going to pay with, and the order in which the students arrive at the cashier, your task is to find out if the cashier will have enough change to return to each of the student when they arrive at the cashier.

Input

The first line of input contains a single integer N (1 ≤ N ≤ 105), the number of students in the queue.

Each of the following N lines describes a student and contains 6 integers, K, F1, F2, F3, F4, and F5, where K represents the amount of money the student has to pay, and Fi (0 ≤ Fi ≤ 100) represents the amount of the ith type of money this student is going to give to the cashier.

The students are given in order; the first student is in front of the cashier.

It is guaranteed that no student will pay any extra notes. In other words, after removing any note from the set the student is going to give to the cashier, the amount of money will be less than what is required to buy the drink.

Output

Print yes if the cashier will have enough change to return to each of the students when they arrive in the given order, otherwise print no.

Examples

Input
3
4 0 1 0 0 0
9 4 1 0 0 0
8 0 0 1 0 0
Output
no
Input
3
9 4 1 0 0 0
4 0 1 0 0 0
8 0 0 1 0 0
Output
yes
题意:第一行输入一个n表示,那个人正在排队,当前售货员没有零钱,接下来又n行,每行有6个数,分别表示所需付的钱,以及1,5,10,20,50元的个数,判断售货员是否可以对每个顾客及时找零。
题解:采用贪心的算法,金额越小越适合找零,能用金额大的找零则用金额大的找零,尽量少用金额小的找零。
具体情况详见代码:
 #include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int main(){
int n;
while(cin>>n)
{
int flag=;
int num1=,num5=,num10=,num20=,num50=,a,b,c,d,e,k;
for(int i=;i<n;i++)
{
cin>>k>>a>>b>>c>>d>>e;
int sum=a+b*+c*+d*+e*; //顾客所拥有的总金额
if(k==sum) //若刚好够,则全部给售货员
{
num1+=a;
num5+=b;
num10+=c;
num20+=d;
num50+=e;
}
if(k<sum)
{
sum=sum-k; //需要找零的钱
if(sum>=&&num50>)
{
if(sum>=num50*)
{ sum-=num50*; //用50找零后还需要再找的零钱
num50=;
}
else
{
sum=sum%;
num50-=sum/;
}
}
if(sum>=&&num20>)
{
if(sum>=num20*)
{ sum-=num20*;
num20=;
}
else
{
sum=sum%;
num20-=sum/;
}
}
if(sum>=&&num10>)
{
if(sum>=num10*)
{ sum-=num10*;
num10=;
}
else
{
sum=sum%;
num10-=sum/;
}
}
if(sum>=&&num5>)
{
if(sum>=num5*)
{ sum-=num5*;
num5=;
}
else
{
sum=sum%;
num5-=sum/;
}
}
if(sum>num1)
flag=;
else
num1-=sum;
num1+=a;
num5+=b;
num10+=c;
num20+=d;
num50+=e;
}
}
if(flag==) cout<<"no"<<endl;
else cout<<"yes"<<endl;
}
return ;
}

Gym - 100989L的更多相关文章

  1. Gym 100989L (DFS)

    AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tr ...

  2. dfs Gym - 100989L

    AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tr ...

  3. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  8. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  9. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

随机推荐

  1. 解读event.returnValue和return false

    前言 首先我们要清楚returnValue是IE的一个属性,如果设置了该属性,它的值比事件句柄的返回值优先级要高,把它的值设置为false,可以取消发生事件源元素的默认动作:return false就 ...

  2. 使用npm安装一些包失败了,更换npm源

    镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry https://regist ...

  3. 通用模块设计UMD

    https://leohxj.gitbooks.io/front-end-database/content/javascript-modules/about-umd.html UMD(universa ...

  4. python之路--基础数据类型的补充与深浅copy

    一 . join的用法 lst =['吴彦祖','谢霆锋','刘德华'] s = '_'.join(lst) print(s) # 吴彦祖_谢霆锋_刘德华 # join() "*" ...

  5. James 3.1服务器的安装与搭建

    参考:1. ububtu下基于docker安装配置Apache James 3.1.0: https://blog.csdn.net/bonwei/article/details/83061372 2 ...

  6. WPF如何实现TreeView节点重命名

    我们经常看到一些软件比如酷狗音乐,在对列表右键进行重命名的时候,当前列表会泛白并且进入可编辑状态,当我们更改完成后就会并进入非编辑状态,这些具体是怎么实现的呢?下面的方法也许会提供一些思路,下面的Tr ...

  7. TField OnValidate 事件

    Occurs just before the data is written to the record buffer. Write an OnValidate event handler to va ...

  8. scss 转为 less

    tnpm install less-plugin-sass2less -g && sass2less **/*.scss {dir}/{name}.less && rm ...

  9. ADO.NET工具类(二)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  10. caffe2学习

    https://www.jianshu.com/p/50bf3bd4e3d0 知乎专栏 https://zhuanlan.zhihu.com/kingbob