結果

問題 No.1015 おつりは要らないです
ユーザー narushima
提出日時 2020-04-03 22:39:13
言語 Java
(openjdk 23)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 2,765 bytes
コンパイル時間 2,991 ms
コンパイル使用メモリ 78,760 KB
実行使用メモリ 47,332 KB
最終ジャッジ日時 2024-11-17 23:13:04
合計ジャッジ時間 12,372 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int x[] = fs.nextIntArray(3);
		int a[] = fs.nextIntArray(n);
		rsort(a);
		for(int i=0;i<n;i++) {
			int t = a[i]/10000;
			if(t>=1) {
				if(x[2]>=t) {
					x[2]-=t;
					a[i]%=10000;
				}
				else {
					a[i]-=x[2]*10000;
					x[2]=0;
				}
			}
		}
		rsort(a);
		for(int i=0;i<n;i++) {
			if(x[2]>0) {//ここで1万円が残ってるなら、もう1万円以上はないので、でかいものから使っていい
				x[2]--;
				a[i]=-1;//OK
				continue;
			}
					
			int t = a[i]/5000;
			if(t>=1) {
				if(x[1]>=t) {
					x[1]-=t;
					a[i]%=5000;
				}
				else {
					a[i]-=x[1]*5000;
					x[1]=0;
				}
			}
		}
		rsort(a);
		for(int i=0;i<n;i++) {
			if(a[i]==-1)continue;
			if(x[2]>0) {
				x[2]--;
				a[i]=-1;//OK
				continue;
			}
			if(x[1]>0) {
				x[1]--;
				a[i]=-1;//OK
				continue;
			}
			int t = a[i]/1000 + 1;
			if(x[0]<t) {
				System.out.println("No");
				return;
			}
			x[0]-=t;
			a[i] = -1;
			
		}
		System.out.println("Yes");
	}
	
	//reverseOrderSort : O(NlogN)
	static void rsort(int[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			int tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}

	static void rsort(long[] ar) {
		Arrays.sort(ar);
		int len = ar.length;
		for (int i = 0; i < len / 2; i++) {
			long tmp = ar[i];
			ar[i] = ar[len - 1 - i];
			ar[len - 1 - i] = tmp;
		}
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}
0