結果

問題 No.1015 おつりは要らないです
ユーザー narushimanarushima
提出日時 2020-04-03 22:39:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 2,765 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 78,684 KB
実行使用メモリ 46,980 KB
最終ジャッジ日時 2024-04-29 01:16:30
合計ジャッジ時間 11,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
37,100 KB
testcase_01 AC 53 ms
36,840 KB
testcase_02 AC 52 ms
36,768 KB
testcase_03 AC 52 ms
37,104 KB
testcase_04 AC 53 ms
37,088 KB
testcase_05 AC 52 ms
37,204 KB
testcase_06 AC 51 ms
37,068 KB
testcase_07 AC 53 ms
37,256 KB
testcase_08 AC 54 ms
36,772 KB
testcase_09 AC 52 ms
37,180 KB
testcase_10 AC 339 ms
46,424 KB
testcase_11 AC 352 ms
46,476 KB
testcase_12 AC 313 ms
46,276 KB
testcase_13 AC 307 ms
46,168 KB
testcase_14 AC 349 ms
46,556 KB
testcase_15 AC 312 ms
46,212 KB
testcase_16 AC 318 ms
46,396 KB
testcase_17 AC 348 ms
46,712 KB
testcase_18 AC 302 ms
45,952 KB
testcase_19 AC 314 ms
46,024 KB
testcase_20 AC 308 ms
46,228 KB
testcase_21 AC 297 ms
46,480 KB
testcase_22 AC 306 ms
46,072 KB
testcase_23 AC 304 ms
46,616 KB
testcase_24 AC 303 ms
46,524 KB
testcase_25 AC 312 ms
46,632 KB
testcase_26 AC 303 ms
46,220 KB
testcase_27 AC 312 ms
46,348 KB
testcase_28 AC 307 ms
46,812 KB
testcase_29 AC 303 ms
46,020 KB
testcase_30 AC 51 ms
36,836 KB
testcase_31 AC 181 ms
43,832 KB
testcase_32 AC 201 ms
44,668 KB
testcase_33 AC 268 ms
46,980 KB
testcase_34 AC 52 ms
36,768 KB
testcase_35 AC 53 ms
36,812 KB
testcase_36 AC 52 ms
37,060 KB
権限があれば一括ダウンロードができます

ソースコード

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