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. Node Buffer 利用 slice + indexOf 生成 split 方法

    demo let buf = Buffer.from('你你我们我你们'); Buffer.prototype.split = function (seq) { let arr=[]; let len ...

  2. Spring Boot 之Profile

    Profile Profile是Spring对不同环境提供不同配置功能的支持,可以通过激活.指定参数等方式快速切换环境. 1)多Profile文件 我们在主配置文件编写的时候,文件名可以是:appli ...

  3. man lspci

    lspci(8)                      Linux PCI Utilities                     lspci(8) NAME       lspci - 列出 ...

  4. 下载csv

    export function downloadCsv(val, key, name, keyName) { if (val.length) { let str = [] str.push(keyNa ...

  5. 从1G到5G,移动通信发展之路

    2G取代1G是历史的必然,诺基亚是2G时代的领航者. 3G是个“半吊子”系统,2G手机只能打电话.发短信,上网很困难.3G的通信标准将信息的传输率提高了一个数量级,这是一个飞跃,它使得移动互联网得以实 ...

  6. mysql OR运算符 语法

    mysql OR运算符 语法 作用:在 WHERE 子语句中把两个或多个条件结合起来. 语法:SELECT * FROM 表名 WHERE 字段1 运算符 值 OR 字段2 运算符 值 说明:如果第一 ...

  7. Supervised pre-trainning有监督预训练

    如我们有一个分类任务,数据库很小,这时还是需要通过预训练来避免深度模型的过拟合问题的,只不过预训练是通过在一个大的数据库上(比如imagenet),通过有监督的训练来完成的.这种有监督预训练加小的数据 ...

  8. 纯CSS手动滑动轮播图(隐藏滚动条)

    HTML: <div class="bigder"> <div class="big"> <dl> <dt>&l ...

  9. mac 外接屏幕切换操作

    mac 屏幕小,可外接合适的屏幕扩展.接好屏幕后: 在 mac 系统变化中看到显示器字样, 点击排列,可以看到一个白色的条状色块,即为主屏幕.(镜像显示不能选中) 在 mac 怎么打开一个应用,在其中 ...

  10. 进阶4:hive 安装

    安装包: apache-hive-2.1.1-bin.tar.gz 安装步骤: 1.上传   apache-hive-2.1.1-bin.tar.gz 到linux; 2.解压文件: tar zxvf ...