結果

問題 No.45 回転寿司
ユーザー joybeeee
提出日時 2020-05-07 15:43:00
言語 Java
(openjdk 23)
結果
AC  
実行時間 178 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 1,861 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 54,960 KB
最終ジャッジ日時 2024-07-03 09:25:56
合計ジャッジ時間 8,094 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int prevPrev = sc.nextInt();
      if(n == 1) {
          System.out.println(prevPrev);
          return;
      }
      
      int prev = Math.max(prevPrev, sc.nextInt());
      int res = Math.max(prevPrev, prev);
      for(int i = 3; i <= n; i++) {
        int num = sc.nextInt();
        res = Math.max(num + prevPrev, prev);
        prevPrev = prev;
        prev = res;
      }
      System.out.println(res);
  }
}
0