結果

問題 No.8044 April Sum of Odd
ユーザー Tententen
提出日時 2020-12-14 10:16:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 78,676 KB
実行使用メモリ 59,236 KB
最終ジャッジ日時 2024-09-20 00:37:19
合計ジャッジ時間 6,621 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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