时间限制:1.0s 内存限制:256.0MB
有n个人正在饭堂排队买海北鸡饭。每份海北鸡饭要25元。奇怪的是,每个人手里只有一张钞票(每张钞票的面值为25、50、100元),而且饭堂阿姨一开始没有任何零钱。请问饭堂阿姨能否给所有人找零(假设饭堂阿姨足够聪明)
第一行一个整数n,表示排队的人数。
接下来n个整数a[1],a[2],...,a[n]。a[i]表示第i位学生手里钞票的价值(i越小,在队伍里越靠前)
接下来n个整数a[1],a[2],...,a[n]。a[i]表示第i位学生手里钞票的价值(i越小,在队伍里越靠前)
输出YES或者NO
4
25 25 50 50
25 25 50 50
YES
2
25 100
25 100
NO
4
25 25 50 100
25 25 50 100
YES
n不超过1000000
一位累死在蓝桥杯的食堂阿姨;
import java.util.*;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int result=0; //初始钱
int temp=0;//中介值
for (int i = 0; i < n; i++) {
temp = sc.nextInt()/25;
if (temp==1) {
result+=1;
}else if (temp==2) {
result+=1;
}else {
result-=3;
}
}
if (result>=0) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
评论 (0)