結果

問題 No.3044 April Sum of Odd
ユーザー TententenTententen
提出日時 2020-12-14 10:16:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 599 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 80,748 KB
実行使用メモリ 62,436 KB
最終ジャッジ日時 2023-10-20 04:54:17
合計ジャッジ時間 6,875 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,448 KB
testcase_01 AC 134 ms
57,652 KB
testcase_02 AC 136 ms
57,460 KB
testcase_03 AC 241 ms
60,480 KB
testcase_04 AC 267 ms
60,476 KB
testcase_05 AC 250 ms
60,388 KB
testcase_06 AC 273 ms
61,164 KB
testcase_07 AC 213 ms
59,692 KB
testcase_08 AC 243 ms
60,524 KB
testcase_09 AC 265 ms
60,900 KB
testcase_10 AC 599 ms
62,436 KB
testcase_11 AC 455 ms
61,648 KB
testcase_12 AC 132 ms
57,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[n];
        int count = 0;
        long sum = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            if (arr[i] % 2 == 1) {
                count++;
                sum += arr[i];
            } else {
                if (count >= m) {
                    sb.append(sum).append("\n");
                }
                count = 0;
                sum = 0;
            }
        }
        if (count >= m) {
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
}
0