結果

問題 No.3103 Range Chmax and Maximize Abs Sum
ユーザー AsahiAsahi
提出日時 2023-03-31 23:17:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,317 bytes
コンパイル時間 3,813 ms
コンパイル使用メモリ 78,736 KB
実行使用メモリ 69,748 KB
最終ジャッジ日時 2023-10-24 09:49:07
合計ジャッジ時間 15,516 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,644 KB
testcase_01 WA -
testcase_02 AC 181 ms
57,628 KB
testcase_03 WA -
testcase_04 AC 131 ms
57,516 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

class Main{

    static void solve(){

        int n = ni();
        long [] A = new long[n];
        for(int i = 0 ; i < n ; i ++ ) {
            A[i] = nl();
        }
        long [] dp = new long[n];
        Arrays.fill(dp,(long)-1e18);
        dp[0] = A[0];
        for(int i = 0 ;i < n-1 ; i++) {
            if(Math.abs(dp[i]) < Math.abs(A[i+1])) { //引き継がない
                dp[i+1] = Math.abs(A[i+1]);
            }
            else {
                dp[i+1] = dp[i];
            }
        }
        long ans = 0;
        for(int i = 0;i < n ; i++) ans += dp[i];
        output.print(ans);
    }

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - //

    static int ni(){ return Integer.parseInt(sc.next()); }
    static long nl(){ return Long.parseLong(sc.next()); }
    static double nd(){ return Double.parseDouble(sc.next()); }
    static String ns(){ return sc.next(); }
    static BigInteger bi(){ return sc.nextBigInteger(); }
    static BigDecimal bd(){ return sc.nextBigDecimal(); }

    static PrintWriter output;
    static Scanner sc ;
    public static void main(String[] args){
        output = new PrintWriter(System.out);
        sc = new Scanner(System.in);
        solve();
        output.flush();
    }

}

0