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. bootstrap模态框动态赋值, ajax异步请求数据后给id为queryInfo的模态框赋值并弹出模态框(JS)

    /查询单个 function query(id) { $.ajax({ url : "/small/productServlet", async : true, type : &q ...

  2. C#读书笔记:线程,任务和同步

    前言 学习C#两个多月了,像当初实习做PHP开发一样,也是由着一个个Feature需求,慢慢掌握了很多相关的编程技巧.本次主要记录下学习C# 多线程的相关知识. 参考书籍:<Csharp高级编程 ...

  3. liunx安装nginx

    参考 https://blog.csdn.net/dyllove98/article/details/41120789 1,去官网下载最新的包 官网地址:http://nginx.org/downlo ...

  4. Python 命令行工具 argparse 模块使用详解

    先来介绍一把最基本的用法 import argparse parser = argparse.ArgumentParser() parser.parse_args() 在执行 parse_args() ...

  5. WorldCount代码检查与优化——软件测试第三次作业

    合作者:201631062222,201631062232 代码地址:https://gitee.com/biubiubiuLYQ/ceshi_secend 本次作业链接地址:https://edu. ...

  6. ArcGIS 添加 MarkerSymbol 弹出“图形符号无法序列化为 JSON”错误

    今天在做一个demo,向自定义图层中添加MarkerSymbol的时候,弹出“图形符号无法序列化为 JSON”错误,之前都没有出现过这个问题,我们首先来看一看我是怎样去添加图层,然后向图层中添加Gra ...

  7. js对json解析获取对应属性的值,JSON.stringify()和JSON.parse()

    JSON.stringify() 该方法,将一个JSON对象转化为字符串string JSON.parse() 该方法,将一个字符串转化为JSON对象object 对于JSON对象,获取其对应键值 可 ...

  8. Stream、FileStream、MemoryStream的区别

    1.Stream:流,在msdn的定义:提供字节序列的一般性视图,Stream提供了读写流的方法是以字节的形式从流中读取内容.而我们经常会用到从字节流中读取文本或者写入文本,微软提供了StreamRe ...

  9. Lodop打印设计里的 打印项对齐

    打印设计界面里,有四个对齐的图标:(1)第一个图标是左右对齐方式,该图标下有四种左右对齐方式.(2)第二个图标是上下对齐方式,该图标下有四种上下对齐方式.(3)第三个图标是等宽对齐,该图标下有三种等宽 ...

  10. jedis集群版应用

    1.pom文件添加依赖: 2.创建配置文件 <!-- jedis集群版配置(JedisCluster通过构造传参(2个参数)) --> <bean id="redisCli ...