結果

問題 No.818 Dinner time
ユーザー chocopuuchocopuu
提出日時 2019-04-19 23:10:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 1,599 ms
コンパイル使用メモリ 170,636 KB
実行使用メモリ 7,756 KB
最終ジャッジ日時 2023-10-24 11:56:56
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
const long long MOD = 1e9 + 7, INF = 1e18;

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N);
    int last = 0, best = 0, dis = 0;
    vector<int> lastmax(N + 1, 0), bestmax(N + 1, 0), dismax(N + 1, 0), sum(N + 1, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i] >> b[i];
        last += max(a[i], b[i]);
        best += a[i];
        sum[i + 1] += sum[i] + a[i];
        chmax(lastmax[i + 1], last);
        chmax(lastmax[i + 1], lastmax[i]);
        chmax(bestmax[i + 1], best);
        chmax(bestmax[i + 1], bestmax[i]);
    }
    dis = sum[N];
    rrep(i, 0, N)
    {
        dis += max(a[i], b[i]);
        dis -= a[i];
        chmax(dismax[i], dis);
        chmax(dismax[i], dismax[i + 1]);
    }

    int ans = dismax[0];
    dismax[N] = bestmax[N];
    for (int i = 1; i < N + 1; i++)
    {
        chmax(ans, dismax[i] + bestmax[i] * (M - 2) + lastmax[i]);
    }
    cout << ans << endl;
}
0