結果

問題 No.505 カードの数式2
ユーザー tenten
提出日時 2020-09-11 08:35:48
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 896 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 75,024 KB
実行使用メモリ 41,556 KB
最終ジャッジ日時 2024-12-24 22:08:29
合計ジャッジ時間 8,592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	long max = sc.nextInt();
    	long min = max;
    	for (int i = 1; i < n; i++) {
    	    long x = sc.nextInt();
    	    long nextMax = max + x;
    	    nextMax = Math.max(nextMax, max - x);
    	    nextMax = Math.max(nextMax, max * x);
    	    nextMax = Math.max(nextMax, min + x);
    	    nextMax = Math.max(nextMax, min - x);
    	    nextMax = Math.max(nextMax, min * x);
    	    long nextMin = max + x;
    	    nextMin = Math.min(nextMin, max - x);
    	    nextMin = Math.min(nextMin, max * x);
    	    nextMin = Math.min(nextMin, min + x);
    	    nextMin = Math.min(nextMin, min - x);
    	    nextMin = Math.min(nextMin, min * x);
    	    max = nextMax;
    	    min = nextMin;
    	}
    	System.out.println(max);
	}
}
0