結果

問題 No.818 Dinner time
ユーザー chocoruskchocorusk
提出日時 2019-04-20 08:53:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 58,696 KB
実行使用メモリ 8,940 KB
最終ジャッジ日時 2023-10-25 21:51:18
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,940 KB
testcase_01 AC 5 ms
8,940 KB
testcase_02 AC 4 ms
8,940 KB
testcase_03 AC 5 ms
8,940 KB
testcase_04 AC 5 ms
8,940 KB
testcase_05 AC 5 ms
8,940 KB
testcase_06 AC 5 ms
8,940 KB
testcase_07 AC 5 ms
8,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
8,940 KB
testcase_11 WA -
testcase_12 AC 5 ms
8,940 KB
testcase_13 AC 5 ms
8,940 KB
testcase_14 AC 5 ms
8,940 KB
testcase_15 AC 5 ms
8,940 KB
testcase_16 AC 5 ms
8,940 KB
testcase_17 AC 51 ms
8,940 KB
testcase_18 AC 35 ms
8,940 KB
testcase_19 AC 39 ms
8,940 KB
testcase_20 AC 48 ms
8,940 KB
testcase_21 AC 46 ms
8,940 KB
testcase_22 AC 37 ms
8,940 KB
testcase_23 AC 42 ms
8,940 KB
testcase_24 AC 57 ms
8,940 KB
testcase_25 AC 41 ms
8,940 KB
testcase_26 AC 35 ms
8,940 KB
testcase_27 AC 49 ms
8,940 KB
testcase_28 AC 41 ms
8,940 KB
testcase_29 AC 56 ms
8,940 KB
testcase_30 WA -
testcase_31 AC 51 ms
8,940 KB
testcase_32 AC 41 ms
8,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll n, m; cin>>n>>m;
    ll a[100001], b[100001];
    ll sa[100001], sa2[100001], sd[100001], mx[100001], sd2[100001];
    sa[0]=sd[0]=sd2[0]=sa2[0]=mx[0]=0;
    for(int i=1; i<=n; i++){
        cin>>a[i]>>b[i];
        if(a[i]>=0){
            sa[i]=sa[i-1]+a[i];
            sa2[i]=sa2[i-1]+a[i];
            sd[i]=sd[i-1]+max(0ll, b[i]-a[i]);
            sd2[i]=sd2[i-1];
        }else{
            sa[i]=sa[i-1]+b[i];
            sa2[i]=sa2[i-1];
            sd[i]=sd[i-1];
            sd2[i]=sd2[i-1]+max(0ll, a[i]-b[i]);
        }
        mx[i]=max(mx[i-1], (m-1)*sa2[i]-sd2[i]);
    }
    ll ans=-1e18;
    for(int i=1; i<=n; i++){
        ans=max(ans, sa[i]+sd[i]+mx[i]+sd2[i]);
    }
    cout<<ans<<endl;
    return 0;
}
0