`
445822357
  • 浏览: 744120 次
文章分类
社区版块
存档分类
最新评论

CF round#202 A (13.09.28)

 
阅读更多
A. Cinema Line
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.

Output

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".

Sample test(s)
Input
4
25 25 50 50
Output
YES
Input
2
25 100
Output
NO
Input
4
50 50 25 25
Output
NO


题意:

上映一部AV, 售价25日元;

钱币在这里按规矩只有三种面额: 25, 50 ,100

很多人排队购买, 初始状态下, 售片方没有钱找零

问, 按给出的队列, 能顺利得让每个人都买到片吗?


做法:

明显找钱的情况只有两种, 收到50的时候找25, 收到100的时候, 找25和50各一张, 即25 + 50 = 75;

并且, 没有情况是需要把100找出去的, 所以只要讨论25 和 50够不够用;

所以, 25 和 50面额的钱币, 收一张, 记一张, 并在找出去的时候记得减去一张;

没应付完一个顾客都要检查是否25 和 50面额的钱币不够用了~


AC代码:

#include<stdio.h>

int main() {
    int num25;
    int num50;
    int n;
    int mark;
    while(scanf("%d", &n) != EOF) {
        num25 = 0;
        num50 = 0;
        mark = 1;
        while(n--) {
            int num;
            scanf("%d", &num);
            if(num == 100) {
                num25--;
                num50--;
            }
            else if(num == 50) {
                num25--;
                num50++;
            }
            else if(num == 25)
                num25++;

            if(num25 < 0 || num50 < 0)
                mark = 0;
        }
        if(mark)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics