結果

問題 No.818 Dinner time
ユーザー veqccveqcc
提出日時 2019-04-19 22:31:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 105,396 KB
実行使用メモリ 6,856 KB
最終ジャッジ日時 2023-10-24 05:15:22
合計ジャッジ時間 2,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 13 ms
5,272 KB
testcase_23 AC 16 ms
5,800 KB
testcase_24 WA -
testcase_25 AC 16 ms
5,800 KB
testcase_26 WA -
testcase_27 AC 19 ms
6,328 KB
testcase_28 AC 16 ms
5,800 KB
testcase_29 WA -
testcase_30 AC 17 ms
6,064 KB
testcase_31 AC 19 ms
6,328 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    ll n, m;
    cin >> n >> m;

    ll a[n], b[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

    vector <ll> opt(n+1, 0);
    vector <ll> mx(n+1, 0);
    for (int i = 0; i < n; i++) {
        opt[i+1] = max(a[i], b[i]) + opt[i];
        mx[i+1] = max(mx[n], opt[i+1]);
    }

    vector <ll> sm(n+1, 0);
    for (int i = 0; i < n; i++) {
        ll val = max({b[i], (m-1)*a[i] + b[i], m*a[i]});
        sm[i+1] = sm[i] + val;
    }

    ll ans = 0;
    for (int k = 0; k <= n; k++) {
        ans = max(ans, sm[k] + (mx[n] - mx[k]));
    }

    cout << ans << "\n";
    return 0;
}
0