結果

問題 No.545 ママの大事な二人の子供
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-07-15 00:05:46
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 808 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 76,200 KB
実行使用メモリ 720,724 KB
最終ジャッジ日時 2024-04-16 20:51:09
合計ジャッジ時間 11,824 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
54,288 KB
testcase_01 AC 132 ms
47,196 KB
testcase_02 AC 131 ms
41,264 KB
testcase_03 AC 132 ms
41,688 KB
testcase_04 AC 132 ms
41,352 KB
testcase_05 AC 133 ms
41,488 KB
testcase_06 AC 133 ms
41,292 KB
testcase_07 AC 132 ms
41,368 KB
testcase_08 AC 134 ms
41,192 KB
testcase_09 AC 135 ms
41,516 KB
testcase_10 AC 136 ms
41,716 KB
testcase_11 AC 135 ms
41,764 KB
testcase_12 AC 142 ms
41,824 KB
testcase_13 AC 148 ms
41,912 KB
testcase_14 AC 134 ms
40,792 KB
testcase_15 AC 122 ms
41,552 KB
testcase_16 AC 160 ms
43,640 KB
testcase_17 AC 183 ms
47,304 KB
testcase_18 AC 493 ms
139,228 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 133 ms
54,128 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long [] B = new long [N];
        ArrayList<Long> L = new ArrayList<>();
        long AMAX = 0;
        for(int i=0; i<N; i++){
            long tmp = sc.nextLong();
            AMAX+=tmp;
            B[i] = tmp+sc.nextLong();
        }
        L.add(AMAX);
        for(int i=0; i<N; i++){
            for(int j=L.size()-1; j>=0; j--){
                long tmp = L.get(j);
                if(tmp<0)continue;
                L.add(L.get(j)-B[i]);
            }
        }
        long ans = AMAX;
        for(int j=L.size()-1; j>=0; j--){
            ans = Math.min(ans,Math.abs(L.get(j)));
        }
        System.out.println(ans);
    }
}
0