結果

問題 No.818 Dinner time
ユーザー ShibuyapShibuyap
提出日時 2020-07-26 15:18:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 200,460 KB
実行使用メモリ 7,080 KB
最終ジャッジ日時 2023-09-11 01:51:33
合計ジャッジ時間 5,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 50 ms
7,000 KB
testcase_18 AC 35 ms
5,752 KB
testcase_19 AC 39 ms
5,864 KB
testcase_20 AC 50 ms
6,772 KB
testcase_21 AC 45 ms
6,240 KB
testcase_22 AC 36 ms
5,528 KB
testcase_23 AC 40 ms
5,912 KB
testcase_24 AC 59 ms
7,080 KB
testcase_25 AC 40 ms
5,924 KB
testcase_26 AC 34 ms
5,600 KB
testcase_27 AC 50 ms
6,684 KB
testcase_28 AC 42 ms
6,076 KB
testcase_29 AC 54 ms
6,796 KB
testcase_30 AC 46 ms
6,288 KB
testcase_31 AC 50 ms
6,552 KB
testcase_32 AC 41 ms
6,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n, m;
    cin >> n >> m;
    ll a[n], b[n];
    rep(i,n)cin >> a[i] >> b[i];

    ll dp[n] = {};
    rep(i,n){
        if(i > 0) dp[i] = dp[i-1];
        if(0 <= a[i] && a[i] <= b[i]){
            dp[i] += (m-1)*a[i] + b[i];
        }else if(0 <= b[i] && b[i] <= a[i]){
            dp[i] += m*a[i];
        }else if(a[i] <= 0 && 0 <= b[i]){
            dp[i] += b[i];
        }else if(b[i] <= 0 && 0 <= a[i]){
            dp[i] += m*a[i];
        }else if(a[i] <= b[i] && b[i] <= 0){
            dp[i] += b[i];
        }else if(b[i] <= a[i] && a[i] <= 0){
            dp[i] += max(m*a[i], b[i]);
        }
    }
    ll ans = -1001001001;
    rep(i,n)ans = max(ans, dp[i]);

    ll dp2[n] = {};
    rep(i,n){
        if(i > 0) dp2[i] = dp2[i-1];
        dp2[i] += max(a[i], b[i]);
    }
    ll dp3[n] = {};
    dp3[n-1] = dp2[n-1];
    drep(i,n-1){
        dp3[i] = max(dp2[i], dp3[i+1]);
    }

    rep(i,n-1){
        ll tmp = dp[i] + dp3[i+1] - dp2[i];
        ans = max(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}
 
 
0