結果

問題 No.818 Dinner time
ユーザー kyort0nkyort0n
提出日時 2019-04-19 22:32:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 167,360 KB
実行使用メモリ 5,148 KB
最終ジャッジ日時 2023-10-24 05:27:49
合計ジャッジ時間 3,156 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 18 ms
5,112 KB
testcase_18 AC 13 ms
4,616 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 14 ms
4,528 KB
testcase_23 AC 16 ms
4,672 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 13 ms
4,496 KB
testcase_27 WA -
testcase_28 AC 15 ms
4,704 KB
testcase_29 AC 20 ms
5,040 KB
testcase_30 AC 17 ms
4,832 KB
testcase_31 AC 18 ms
4,916 KB
testcase_32 AC 15 ms
4,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, M;
ll A[100050];
ll B[100050];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];
    ll ans = 0;
    ll now = 0;
    int last = 0;
    for(int i = 1; i <= N; i++) {
        now += max(A[i], B[i]);
        if(ans <= now) {
            ans = max(ans, now);
            last = i;
        }
    }
    ll ans2 = 0;
    now = 0;
    for(int i = 1; i <= N; i++) {
        if(A[i] >= 0) {
            now += (M - 1) * A[i];
            ans2 = max(ans2, now);
            continue;
        }
        if(B[i] >= A[i]) {
            if(last < i) now += B[i];
            continue;
        }
        ll val = max((M - 1) * A[i], B[i]);
        if(last >= i) val = max(val, B[i] - A[i]);
        now += val;
        ans2 = max(ans2, now);
    }
    cout << ans + ans2 << endl;
    return 0;
}
0