結果

問題 No.818 Dinner time
ユーザー betrue12betrue12
提出日時 2019-04-19 23:26:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 165,976 KB
実行使用メモリ 4,944 KB
最終ジャッジ日時 2023-08-20 00:51:31
合計ジャッジ時間 3,450 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 47 ms
4,944 KB
testcase_18 AC 33 ms
4,380 KB
testcase_19 AC 36 ms
4,544 KB
testcase_20 AC 47 ms
4,648 KB
testcase_21 AC 42 ms
4,528 KB
testcase_22 AC 33 ms
4,376 KB
testcase_23 AC 39 ms
4,380 KB
testcase_24 AC 55 ms
4,896 KB
testcase_25 AC 37 ms
4,412 KB
testcase_26 AC 32 ms
4,380 KB
testcase_27 AC 47 ms
4,784 KB
testcase_28 AC 39 ms
4,376 KB
testcase_29 AC 52 ms
4,676 KB
testcase_30 AC 44 ms
4,560 KB
testcase_31 AC 47 ms
4,556 KB
testcase_32 AC 38 ms
4,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int64_t N, M, A[100000], B[100000];
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    int64_t a = 0, b = 0, c = 0;
    int64_t ans = -1e18;
    for(int i=0; i<N; i++){
        if(A[i] < 0 && B[i] < 0){
            a += A[i];
            b += max(A[i], B[i]);
            c += max(M*A[i], B[i]);
        }else{
            int64_t x, y;
            if(A[i] >= 0){
                x = A[i];
                y = max(A[i], B[i]);
            }else{
                x = 0;
                y = B[i];
            }
            a += x;
            b += y;
            c += (M-1)*x + y;
        }
        if(i == 0 || b <= c){
            a = 0;
            b = c;
            ans = max(ans, c);
        }else{
            ans = max({ans, b, c});
        }
    }
    cout << ans << endl;
    return 0;
}
0