結果

問題 No.1015 おつりは要らないです
ユーザー narushimanarushima
提出日時 2020-04-03 22:36:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,739 bytes
コンパイル時間 2,615 ms
コンパイル使用メモリ 74,476 KB
実行使用メモリ 58,108 KB
最終ジャッジ日時 2023-09-16 03:30:52
合計ジャッジ時間 11,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,324 KB
testcase_01 AC 45 ms
49,064 KB
testcase_02 AC 45 ms
49,220 KB
testcase_03 AC 44 ms
49,164 KB
testcase_04 AC 44 ms
49,224 KB
testcase_05 AC 46 ms
49,028 KB
testcase_06 AC 45 ms
49,204 KB
testcase_07 AC 45 ms
49,444 KB
testcase_08 AC 45 ms
49,064 KB
testcase_09 AC 45 ms
49,228 KB
testcase_10 AC 325 ms
58,108 KB
testcase_11 AC 316 ms
57,264 KB
testcase_12 AC 329 ms
57,344 KB
testcase_13 AC 334 ms
57,484 KB
testcase_14 AC 334 ms
57,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 314 ms
57,232 KB
testcase_21 AC 292 ms
56,828 KB
testcase_22 AC 309 ms
56,520 KB
testcase_23 AC 291 ms
57,396 KB
testcase_24 AC 309 ms
56,788 KB
testcase_25 AC 302 ms
56,900 KB
testcase_26 AC 293 ms
57,168 KB
testcase_27 AC 301 ms
56,744 KB
testcase_28 AC 306 ms
57,608 KB
testcase_29 AC 324 ms
56,992 KB
testcase_30 AC 44 ms
47,564 KB
testcase_31 AC 181 ms
55,952 KB
testcase_32 AC 188 ms
56,828 KB
testcase_33 AC 247 ms
58,008 KB
testcase_34 AC 45 ms
49,208 KB
testcase_35 AC 44 ms
49,236 KB
testcase_36 AC 46 ms
47,404 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;
				}
			}
		}
		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;
				}
			}
		}
		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