http://codeforces.com/contest/349

2021-06-29 00:06

阅读:394

标签:题解   i++   office   number   other   tle   end   force   clu   

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 equals25, 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".

Examples
input
4
25 25 50 50
output
YES
input
2
25 100
output
NO
input
4
50 50 25 25
output
NO

简介:买电影票一张25一张,然后营业员最初没有钱,给你一个只有25 ,50,100的数列,问能否成功卖票,成功输出“yes”否则输出“NO”

题解:直接模拟,x代表25的票数y代表50的票数z代表100的票数

代码如下:

 1 #include 2 #include 3 #include 4 using namespace std;
 5 const int maxn=1e5+5; 
 6 int a[maxn];
 7 int x,y,z,n; 
 8 int main()
 9 {
10     scanf("%d",&n);
11     int flag=true;
12     x=y=z=0; 
13     for(int i=0;i)
14     {
15         scanf("%d",&a[i]);
16         if(flag) 
17         {
18             if(a[i]==25)
19             {
20                 x++; 
21             }
22             else if(a[i]==50) 
23             {
24                 y++;
25                 if(x>=1)
26                 {
27                     x--; 
28                 }
29                 else
30                 {
31                     flag=false; 
32                 } 
33             } 
34             else 
35             {
36                 z++; 
37                 if(y>=1&&x>=1)
38                 {
39                     y--;
40                     x--; 
41                 }
42                 else if(x>=3) 
43                 {
44                     x=x-3; 
45                 } 
46                 else
47                 {
48                     flag=false; 
49                 } 
50             } 
51             
52         } 
53         
54     } 
55     if(flag)
56     {
57         cout"YES\n"; 
58     } 
59     else
60     {
61         cout"NO\n"; 
62     } 
63 } 

题目连接http://codeforces.com/contest/349/problem/A

http://codeforces.com/contest/349

标签:题解   i++   office   number   other   tle   end   force   clu   

原文地址:http://www.cnblogs.com/lhclqslove/p/7142383.html


评论


亲,登录后才可以留言!