結果

問題 No.198 キャンディー・ボックス2
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 23:11:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 41,696 KB
最終ジャッジ日時 2024-07-18 21:47:02
合計ジャッジ時間 6,953 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
40,340 KB
testcase_01 AC 116 ms
41,168 KB
testcase_02 AC 116 ms
41,124 KB
testcase_03 AC 114 ms
40,136 KB
testcase_04 AC 124 ms
41,268 KB
testcase_05 AC 122 ms
41,424 KB
testcase_06 AC 109 ms
40,368 KB
testcase_07 AC 128 ms
41,452 KB
testcase_08 AC 123 ms
41,292 KB
testcase_09 AC 126 ms
41,164 KB
testcase_10 AC 107 ms
41,444 KB
testcase_11 AC 115 ms
40,132 KB
testcase_12 AC 119 ms
41,492 KB
testcase_13 AC 122 ms
41,516 KB
testcase_14 AC 123 ms
41,100 KB
testcase_15 AC 122 ms
41,468 KB
testcase_16 AC 127 ms
41,520 KB
testcase_17 AC 125 ms
41,304 KB
testcase_18 AC 121 ms
41,240 KB
testcase_19 AC 112 ms
41,356 KB
testcase_20 AC 106 ms
40,172 KB
testcase_21 WA -
testcase_22 AC 126 ms
41,160 KB
testcase_23 WA -
testcase_24 AC 124 ms
41,696 KB
testcase_25 WA -
testcase_26 AC 128 ms
41,124 KB
testcase_27 AC 116 ms
41,296 KB
testcase_28 WA -
testcase_29 AC 110 ms
41,292 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[i] - arr[pos]);
				current_score += Math.abs(arr[pos] - arr[i]);
			}
			
			if(benefit < 0){ continue; }
			
			score = Math.min(score, current_score);
			//System.out.println(pos + " " + arr[pos] + " " + current_score);
		}
		
		System.out.println(score);

	}

}
0