http://codeforces.com/gym/100989/problem/H

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
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <ctype.h>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 10
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int sum , sum1 , sum5 , sum10 , sum20 , sum50 ; int main()
{
int n ;
scanf("%d" , &n);
int flag = ;
for(int i = ; i < n ; i++)
{
int x , n1 , n5 , n10 , n20 , n50;
scanf("%d%d%d%d%d%d" , &x , &n1 , &n5 , &n10 , &n20 , &n50);
sum = * n1 + *n5 + *n10 + *n20 + *n50 - x;
while(sum >= && sum50)
{
sum -= ;
sum50 -- ;
}
while(sum >= && sum20)
{
sum -= ;
sum20 -- ;
}
while(sum >= && sum10)
{
sum -= ;
sum10 -- ;
}
while(sum >= && sum5)
{
sum -= ;
sum5 -- ;
}
while(sum >= && sum1)
{
sum -= ;
sum1 -- ;
}
if(sum == )
{
sum1 += n1 ;
sum5 += n5 ;
sum10 += n10;
sum20 += n20;
sum50 += n50;
}
else
{
flag = ;
}
}
if(flag)
{
printf("no\n");
}
else
{
printf("yes\n");
} return ;
}

贪心(change)的更多相关文章

  1. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  2. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Codeforces Round #370 (Div. 2) A B C 水 模拟 贪心

    A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. CF 500 C. New Year Book Reading 贪心 简单题

    New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n b ...

  5. leetcode:Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  6. HDU 5821 Ball (贪心)

    Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes nu ...

  7. Codeforces Gym 100203E E - bits-Equalizer 贪心

    E - bits-EqualizerTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest ...

  8. POJ - 2965 - The Pilots Brothers&#39; refrigerator (高效贪心!!)

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19356 ...

  9. CF Covered Path (贪心)

    Covered Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

随机推荐

  1. 【leetcode】1156. Swap For Longest Repeated Character Substring

    题目如下: Given a string text, we are allowed to swap two of the characters in the string. Find the leng ...

  2. Alter改变终结

    #alter#删除date列但若表中只有一个字段无法使用drop删除ALTER TABLE z_staff_info_copy1 DROP `date`;ALTER TABLE z_staff_inf ...

  3. 【JavaScript】包装类

    包装类 String().Number().Boolean() String() 可以将基本数据类型的字符串转换为String对象 var string = new String("hell ...

  4. js-点出弹框后(除了点击窗口上的叉子),点其他地方能够关闭窗口???

    HTML: <div class="A"> <div class="B"></div> </div> JS: $ ...

  5. Java中日期

    package com.shiro.springbootshiro; import java.text.SimpleDateFormat; import java.util.Date; /** * 作 ...

  6. java.util.Properties的使用及读取资源文件

    1.工具类Utils package com.oy.utils; import java.io.BufferedInputStream; import java.io.Closeable; impor ...

  7. docker 安装MongoDB以及设置用户

    MongoDB 是一个免费的开源跨平台面向文档的 NoSQL 数据库程序. 1.查看可用的 MongoDB 版本 访问 MongoDB 镜像库地址: https://hub.docker.com/_/ ...

  8. IIS新建项目

    我在写网站的时候要 经常帮公司的游戏写界面,他们用的都是VS,然后要用IIS创建项目(配置环境)然后页面才能够在浏览器上看效果. 那就要先了解啥是IIS: IIS是Internet Informati ...

  9. XXX is not a function

    今天,一个以前的小伙伴跟我说他遇到了一个问题,调试了将近两天(这家伙一开始不打算干程序员,跑去干了两个月销售,现在又想回来写代码了,所以就自己折腾一个demo,免得面试的时候被问住) 我把他的代码从头 ...

  10. iOS-KMNavigationBarTransition 框架学习

    最后更新: 2017-06-21 一.文件结构 二.KMSwizzle KMSwizzle主要就一个方法交换的代码 2.1 class_getInstanceMethod() 获取某个类实例的方法, ...