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. 小程序wepy.js框架总结

    wepy.js借鉴了Vue的语法风格和功能特性,对官方提供的框架进行了封装,更贴近于MVVM架构模式,让开发者更加容易上手,增加开发效率.(脏数据处理--是否有标识.是否有响应) 前端开发的对组件化开 ...

  2. [转帖]中关村:LED屏幕和OLED屏幕有什么区别?答案在这里

    LED屏幕和OLED屏幕有什么区别?答案在这里   中关村在线 01-0810:40 目前的电视市场,更新换代的频率越来越快,无论是国产品牌还是合资品牌,都不约而同的推出了全新产品.这离不开人们对更好 ...

  3. Laravel 5.2+ 使用url()全局函数返回前一个页面的地址

    注意:文章标题中5.2+表示该文章内容可向上兼容,适用于Laravel版本5.2及更高(目前最新为5.6),但不可向下兼容,即不适用于5.2版本以下.推荐大家花一点点时间,将自己的Laravel更新至 ...

  4. Java——scoket通讯

    Socket 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. Socket是TCP/IP协议通信的抽象层,所以我们还需要了解TCP协议 传输层协议 TCP: ...

  5. 如何确定 Hadoop map和reduce的个数--map和reduce数量之间的关系是什么?

    1.map和reduce的数量过多会导致什么情况?2.Reduce可以通过什么设置来增加任务个数?3.一个task的map数量由谁来决定?4.一个task的reduce数量由谁来决定? 一般情况下,在 ...

  6. python数学第五天【常用概率分布】

    1. 概率基本公式 思考题: 3. 两点分布 4. 二项分布 推论一: 5.柏松分布 6. 均匀分布 7. 指数分布 8. 正态分布 9.常见分布的总结

  7. Druid数据库连接池

    一.Druid连接池的创建 package cn.zhouzhou; import java.io.IOException; import java.io.InputStream; import ja ...

  8. linux 依赖解决办法

    在安装软件过程中如果出现依赖不满足,有两种情况: 1:你系统里面没有安装依赖软件,[但是你的软件源里面有这个软件,你只是没有安装], 这种情况很简单,通过 sudo apt-get install - ...

  9. 今日头条移动app广告激活数据API对接完整Java代码实现供大家参考》》》项目随记

    这是自毕业后的第一篇博客,希望自己今后能养成写博客的一个好习惯.最近公司为了加速APP推广,采取在外部平台(如:今日头条)进行广告投放的方式,进行用户引流.因此我们需要对广告的激活数据进行一个检测,跟 ...

  10. 给dom对象添加事件