結果

問題 No.1015 おつりは要らないです
ユーザー narushimanarushima
提出日時 2020-04-03 22:39:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 2,765 bytes
コンパイル時間 4,358 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 58,196 KB
最終ジャッジ日時 2023-08-11 08:44:22
合計ジャッジ時間 13,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,464 KB
testcase_01 AC 43 ms
50,020 KB
testcase_02 AC 43 ms
49,588 KB
testcase_03 AC 44 ms
49,552 KB
testcase_04 AC 44 ms
49,852 KB
testcase_05 AC 43 ms
49,524 KB
testcase_06 AC 44 ms
49,540 KB
testcase_07 AC 44 ms
49,548 KB
testcase_08 AC 44 ms
49,628 KB
testcase_09 AC 45 ms
49,636 KB
testcase_10 AC 321 ms
58,196 KB
testcase_11 AC 307 ms
43,336 KB
testcase_12 AC 284 ms
43,756 KB
testcase_13 AC 302 ms
43,852 KB
testcase_14 AC 309 ms
43,608 KB
testcase_15 AC 306 ms
43,248 KB
testcase_16 AC 310 ms
43,288 KB
testcase_17 AC 316 ms
43,272 KB
testcase_18 AC 320 ms
42,936 KB
testcase_19 AC 321 ms
43,176 KB
testcase_20 AC 289 ms
43,128 KB
testcase_21 AC 284 ms
44,224 KB
testcase_22 AC 278 ms
43,180 KB
testcase_23 AC 280 ms
43,204 KB
testcase_24 AC 313 ms
43,488 KB
testcase_25 AC 293 ms
43,196 KB
testcase_26 AC 282 ms
43,416 KB
testcase_27 AC 301 ms
43,232 KB
testcase_28 AC 278 ms
43,240 KB
testcase_29 AC 286 ms
43,776 KB
testcase_30 AC 39 ms
33,816 KB
testcase_31 AC 159 ms
41,144 KB
testcase_32 AC 177 ms
41,516 KB
testcase_33 AC 234 ms
43,852 KB
testcase_34 AC 41 ms
33,488 KB
testcase_35 AC 44 ms
33,484 KB
testcase_36 AC 44 ms
49,548 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