結果

問題 No.198 キャンディー・ボックス2
ユーザー uafr_csuafr_cs
提出日時 2015-09-02 23:11:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 5,058 ms
コンパイル使用メモリ 72,196 KB
実行使用メモリ 58,220 KB
最終ジャッジ日時 2023-09-26 02:25:37
合計ジャッジ時間 7,455 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,252 KB
testcase_01 AC 126 ms
55,544 KB
testcase_02 AC 126 ms
55,876 KB
testcase_03 AC 124 ms
55,820 KB
testcase_04 AC 126 ms
55,796 KB
testcase_05 AC 126 ms
55,756 KB
testcase_06 AC 125 ms
55,772 KB
testcase_07 AC 125 ms
55,808 KB
testcase_08 AC 125 ms
55,896 KB
testcase_09 AC 125 ms
56,312 KB
testcase_10 AC 125 ms
54,100 KB
testcase_11 AC 124 ms
55,504 KB
testcase_12 AC 125 ms
55,812 KB
testcase_13 AC 126 ms
55,900 KB
testcase_14 AC 125 ms
55,848 KB
testcase_15 AC 122 ms
56,260 KB
testcase_16 AC 126 ms
55,880 KB
testcase_17 AC 122 ms
55,808 KB
testcase_18 AC 123 ms
55,576 KB
testcase_19 AC 124 ms
55,980 KB
testcase_20 AC 123 ms
55,936 KB
testcase_21 WA -
testcase_22 AC 126 ms
55,908 KB
testcase_23 WA -
testcase_24 AC 126 ms
55,972 KB
testcase_25 WA -
testcase_26 AC 127 ms
55,964 KB
testcase_27 AC 125 ms
55,768 KB
testcase_28 WA -
testcase_29 AC 126 ms
55,884 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