結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2020-05-25 10:27:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 184 ms / 5,000 ms |
コード長 | 814 bytes |
コンパイル時間 | 2,042 ms |
コンパイル使用メモリ | 73,912 KB |
実行使用メモリ | 42,688 KB |
最終ジャッジ日時 | 2024-10-13 02:01:41 |
合計ジャッジ時間 | 8,515 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sushiNum = sc.nextInt(); int[] sushiTastes = new int[sushiNum]; for (int i = 0; i < sushiNum; i++) { sushiTastes[i] = sc.nextInt(); } int ret = new Main().execute(sushiTastes); System.out.println(ret); } int execute(int[] sushiTastes) { int lastOnMaxTasteSum = 0; int lastOffMaxTasteSum = 0; for (int taste : sushiTastes) { int newLastOnMaxTasteSum = lastOffMaxTasteSum + taste; int newLastOffMaxTasteSum = lastOnMaxTasteSum; lastOnMaxTasteSum = newLastOnMaxTasteSum; if (lastOffMaxTasteSum <= newLastOffMaxTasteSum) { lastOffMaxTasteSum = newLastOffMaxTasteSum; } } return Math.max(lastOnMaxTasteSum, lastOffMaxTasteSum); } }