现在的位置: 首页 > 综合 > 正文

CF水题

2013年03月18日 ⁄ 综合 ⁄ 共 2097字 ⁄ 字号 评论关闭
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 10050 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 equals2550 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

/*
 * Author:  *****
 * Created Time:  2013/9/27 23:04:50
 * File Name: F.cpp
 * solve: F.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<iostream>
#include<vector>
#include<queue>
//ios_base::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
#define sqr(x) ((x) * (x))
typedef long long LL;

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 30000;

int sgn(const double &x) {  return (x > eps) - (x < -eps); }

int used[200];
int main() 
{
    //freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    clr(used);
    
    int flag = 1;
    rep(i,0,n)
    {
        int a;
        scanf("%d",&a);
        if(a == 25)
        {
             used[25]++;
             continue;
        }
        if(a == 50 )
        {
            used[50]++;
            if(used[25])
            {
                used[25]--;
                continue;
            }
            else
            {
                flag = 0;
                break;
            }
        }
        
        if(a == 100)
        {
            used[100]++;
            if(used[25] && used[50])
            {
                used[25]--;
                used[50]--;
                continue;
            }
            
            if(used[25] == 0)
            {
                flag = 0;
                break;
            }
            
            if(used[25]<3 && used[50] == 0)
            {
                flag = 0;
                break;
            }
            if(used[25] >= 3)
             used[25] -= 3;
        }
    }
    
    if(flag)
        cout<<"YES\n";
    else
        cout<<"NO\n";
    return 0;
}

抱歉!评论已关闭.