結果

問題 No.3044 April Sum of Odd
ユーザー joybeeeejoybeeee
提出日時 2020-05-14 15:31:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 559 ms / 2,000 ms
コード長 627 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 71,660 KB
実行使用メモリ 62,584 KB
最終ジャッジ日時 2023-10-13 10:45:46
合計ジャッジ時間 6,790 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,844 KB
testcase_01 AC 123 ms
56,080 KB
testcase_02 AC 124 ms
55,732 KB
testcase_03 AC 234 ms
58,920 KB
testcase_04 AC 263 ms
58,092 KB
testcase_05 AC 274 ms
59,944 KB
testcase_06 AC 294 ms
60,448 KB
testcase_07 AC 205 ms
58,576 KB
testcase_08 AC 231 ms
59,112 KB
testcase_09 AC 281 ms
60,180 KB
testcase_10 AC 559 ms
62,584 KB
testcase_11 AC 486 ms
60,348 KB
testcase_12 AC 121 ms
55,820 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 m = sc.nextInt();
      int[] arr = new int[n];
      for(int i = 0; i < n; i++)
        arr[i] = sc.nextInt();
      int leftIdx = 0;
      long sum = 0L;
      for(int i = 0; i < n; i++) {
        if(arr[i] % 2 == 1) {
          sum += arr[i];
        } else {
          if(i - leftIdx >= m)
            System.out.println(sum);
          sum = 0L;
          leftIdx = i + 1;
        }
      }
      if(n - leftIdx >= m)
        System.out.println(sum);
  }
}
0