CF349A.Cinema Line

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

全新《虎胆龙威》电影刚刚上映!电影院售票处排起了长长的队伍,队伍中有 n 个人。每个人手中都只有一张 100、50 或 25 卢布的钞票。“《虎胆龙威》”电影票售价为 25 卢布。假设售票员初始时没有任何零钱,并且必须严格按照队伍中人员的顺序售票,他能否为每个人成功售出一张票并找零?

输入格式

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.

第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)—— 表示队列中的人数。
第二行包含 nn 个整数,每个数为 2525、5050 或 100100 —— 表示每个人所持钞票的面值。这些数字按队列顺序给出(从队首(售票处)到队尾)。

输出格式

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

如果售票员能向每位顾客出售一张票并找零,则输出 "YES"(不带引号);否则输出 "NO"。

输入输出样例

  • 输入#1

    4
    25 25 50 50

    输出#1

    YES
  • 输入#2

    2
    25 100

    输出#2

    NO
  • 输入#3

    4
    50 50 25 25

    输出#3

    NO

输入解题思路,AI测评打分。不知道怎么写?

首页