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. Python3练习题 006 冒泡排序

    import random a = [random.randint(1,100) for i in range(10)]def bu(target): length = len(target) whi ...

  2. React Native之微信分享(iOS Android)

    React Native之微信分享(iOS Android) 在使用React Native开发项目的时候,基本都会使用到微信好友或者微信朋友圈分享功能吧,那么今天我就带大家实现以下RN微信好友以及朋 ...

  3. a标签中的onclick和href的使用

    onclick和href 链接的 onclick 事件被先执行,其次是 href 属性下的动作(页面跳转,或 javascript 伪链接):  假设链接中同时存在 href 与 onclick,如果 ...

  4. vue二次实战(二)

    https://www.cnblogs.com/jellify/p/9522477.html install的弹出框中输入sublimeTmpl,找到sublimeTmpl这个插件后回车 Vue路由 ...

  5. cordova微信支付回调App闪退

    这是cordova版本太高,不兼容这个插件所导致的.解决方案是修改$your_project/plugins/cordova-plugin-wechat/scripts/android-install ...

  6. j收集ava面试题

    史上最全Java面试题(带全部答案) https://blog.csdn.net/linzhiqiang0316/article/details/80473906

  7. shell自定义输入输出 read+echo

    自定义格式输入.输出(244)  输出:echo -e 解释转义字符 -n  回车不换行 \n   新的一行,等同于回车 \t 制表符 \r 回车 \b 回退 baskspace 删除键 演示\n \ ...

  8. QTP 自动货测试桌面程序-笔记-运行结果中添加截图

    3种方法: 方法1:使用设置:SnapshotReportMode oldMode = Setting("SnapshotReportMode") Setting("Sn ...

  9. How to remove unwant Internet Explorer Context Menu

    HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt

  10. Nginx 热部署最版本

    L10 进入nginx里的sbin目录 拷贝原先的做备份 cp nginx nginx.old 然后将已经编译好的nginx二进制文件复制到sbin目录下并覆盖原有的二进制文件 kill -USR2 ...