結果

問題 No.198 キャンディー・ボックス2
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 22:46:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 794 bytes
コンパイル時間 4,550 ms
コンパイル使用メモリ 72,588 KB
実行使用メモリ 58,060 KB
最終ジャッジ日時 2023-09-26 02:22:55
合計ジャッジ時間 8,737 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,872 KB
testcase_01 AC 127 ms
56,004 KB
testcase_02 AC 124 ms
55,764 KB
testcase_03 AC 123 ms
55,976 KB
testcase_04 AC 123 ms
56,444 KB
testcase_05 AC 124 ms
55,880 KB
testcase_06 AC 124 ms
56,356 KB
testcase_07 AC 125 ms
56,024 KB
testcase_08 AC 125 ms
53,664 KB
testcase_09 AC 124 ms
56,260 KB
testcase_10 AC 124 ms
56,316 KB
testcase_11 AC 121 ms
55,728 KB
testcase_12 AC 121 ms
55,956 KB
testcase_13 WA -
testcase_14 AC 126 ms
55,900 KB
testcase_15 AC 126 ms
55,760 KB
testcase_16 AC 123 ms
54,468 KB
testcase_17 AC 125 ms
56,012 KB
testcase_18 AC 123 ms
56,308 KB
testcase_19 WA -
testcase_20 AC 123 ms
55,968 KB
testcase_21 WA -
testcase_22 AC 125 ms
56,564 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 124 ms
55,728 KB
testcase_27 AC 124 ms
56,112 KB
testcase_28 WA -
testcase_29 AC 123 ms
55,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final long B = sc.nextLong();
		final int N = sc.nextInt();
		
		long[] arr = new long[N];
		for(int i = 0; i < N; i++){
			final long c = sc.nextLong();
		
			arr[i] = c;
		}
		
		Arrays.sort(arr);
		
		long score = Long.MAX_VALUE;
		for(int pos = 0; pos < N; pos++){
			long benefit = B, current_score = 0;
			
			for(int i = 0; i < N; i++){
				benefit += (arr[pos] - arr[i]);
				current_score += Math.abs(arr[pos] - arr[i]);
			}
			
			if(benefit < 0){ continue; }
			
			score = Math.min(score, current_score);
		}
		
		System.out.println(score);

	}

}
0