結果

問題 No.115 遠足のおやつ
ユーザー tentententen
提出日時 2020-11-17 19:45:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 1,121 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 74,052 KB
実行使用メモリ 57,920 KB
最終ジャッジ日時 2023-08-31 01:00:30
合計ジャッジ時間 9,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,668 KB
testcase_01 AC 125 ms
56,060 KB
testcase_02 AC 125 ms
56,044 KB
testcase_03 AC 125 ms
57,920 KB
testcase_04 AC 122 ms
55,864 KB
testcase_05 AC 122 ms
55,800 KB
testcase_06 AC 123 ms
55,924 KB
testcase_07 AC 123 ms
56,352 KB
testcase_08 AC 124 ms
55,568 KB
testcase_09 AC 124 ms
56,396 KB
testcase_10 AC 122 ms
56,164 KB
testcase_11 AC 125 ms
56,156 KB
testcase_12 AC 124 ms
56,036 KB
testcase_13 AC 121 ms
55,544 KB
testcase_14 AC 126 ms
55,720 KB
testcase_15 AC 125 ms
55,800 KB
testcase_16 AC 125 ms
56,176 KB
testcase_17 AC 125 ms
56,068 KB
testcase_18 AC 124 ms
56,044 KB
testcase_19 AC 124 ms
55,940 KB
testcase_20 AC 125 ms
55,784 KB
testcase_21 AC 124 ms
55,580 KB
testcase_22 AC 125 ms
56,040 KB
testcase_23 AC 124 ms
56,044 KB
testcase_24 AC 125 ms
55,836 KB
testcase_25 AC 122 ms
55,856 KB
testcase_26 AC 121 ms
56,272 KB
testcase_27 AC 122 ms
55,860 KB
testcase_28 AC 123 ms
55,988 KB
testcase_29 AC 126 ms
56,092 KB
testcase_30 AC 125 ms
55,788 KB
testcase_31 AC 123 ms
55,916 KB
testcase_32 AC 124 ms
56,220 KB
testcase_33 AC 122 ms
55,796 KB
testcase_34 AC 122 ms
56,368 KB
testcase_35 AC 123 ms
55,776 KB
testcase_36 AC 125 ms
56,072 KB
testcase_37 AC 124 ms
56,280 KB
testcase_38 AC 124 ms
55,812 KB
testcase_39 AC 122 ms
55,740 KB
testcase_40 AC 122 ms
56,128 KB
testcase_41 AC 122 ms
54,464 KB
testcase_42 AC 123 ms
55,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[k];
        for (int i = 0; i < k; i++) {
            arr[i] = i + 1;
            d -= i + 1;
        }
        if (d < 0 || n < k) {
            System.out.println(-1);
            return;
        }
        int max = n;
        for (int i = k - 1; i >= 0 && d > 0; i--) {
            if (d + arr[i] - max >= 0) {
                d += arr[i];
                arr[i] = max;
                d -= max;
                max--;
            } else {
                arr[i] += d;
                d = 0;
            }
        }
        if (d > 0) {
            System.out.println(-1);
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < k; i++) {
                if (i > 0) {
                    sb.append(" ");
                }
                sb.append(arr[i]);
            }
            System.out.println(sb);
        }
    }
}
0