結果

問題 No.545 ママの大事な二人の子供
ユーザー mosmos_21mosmos_21
提出日時 2017-07-14 22:43:55
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 678 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 74,880 KB
実行使用メモリ 41,976 KB
最終ジャッジ日時 2024-04-16 20:36:31
合計ジャッジ時間 6,964 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 121 ms
41,304 KB
testcase_02 AC 128 ms
41,472 KB
testcase_03 AC 128 ms
41,208 KB
testcase_04 AC 125 ms
41,432 KB
testcase_05 AC 126 ms
41,736 KB
testcase_06 WA -
testcase_07 AC 122 ms
41,268 KB
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 AC 126 ms
41,448 KB
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    Scanner in = new Scanner(System.in);

    public void solve() {
        int n = in.nextInt();
        int[] a = new int[n], b = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }
        int ap = 0, bp = 0;
        for(int i = 0; i < n; i++){
            if(Math.abs(ap + a[i] - bp) < Math.abs(bp + b[i] - ap)){
                ap += a[i];
            }else{
                bp += b[i];
            }
        }
        System.out.println(Math.abs(ap - bp));
        
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}
0