結果

問題 No.818 Dinner time
ユーザー pekempeypekempey
提出日時 2019-04-19 22:07:56
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 525 ms
使用メモリ 6,848 KB
最終ジャッジ日時 2023-01-06 05:11:01
合計ジャッジ時間 2,994 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,400 KB
testcase_01 AC 1 ms
3,532 KB
testcase_02 AC 2 ms
3,448 KB
testcase_03 AC 1 ms
3,512 KB
testcase_04 AC 1 ms
3,504 KB
testcase_05 AC 1 ms
3,532 KB
testcase_06 AC 1 ms
3,448 KB
testcase_07 AC 1 ms
3,484 KB
testcase_08 AC 1 ms
3,428 KB
testcase_09 AC 2 ms
3,448 KB
testcase_10 AC 1 ms
3,532 KB
testcase_11 AC 1 ms
3,432 KB
testcase_12 AC 2 ms
3,380 KB
testcase_13 AC 2 ms
3,496 KB
testcase_14 AC 2 ms
3,528 KB
testcase_15 AC 1 ms
3,544 KB
testcase_16 AC 1 ms
3,392 KB
testcase_17 AC 47 ms
6,736 KB
testcase_18 AC 33 ms
5,420 KB
testcase_19 AC 36 ms
5,540 KB
testcase_20 AC 47 ms
6,600 KB
testcase_21 AC 43 ms
5,944 KB
testcase_22 AC 34 ms
5,152 KB
testcase_23 AC 39 ms
5,676 KB
testcase_24 AC 55 ms
6,848 KB
testcase_25 AC 38 ms
5,488 KB
testcase_26 AC 32 ms
5,148 KB
testcase_27 AC 48 ms
6,248 KB
testcase_28 AC 39 ms
5,768 KB
testcase_29 AC 52 ms
6,544 KB
testcase_30 AC 44 ms
5,948 KB
testcase_31 AC 47 ms
6,212 KB
testcase_32 AC 39 ms
5,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

long long dp0[100001];
long long dp1[100001];
long long dp2[100001];

void to(long long &x, long long y) {
  x = max(x, y);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> A(N), B(N);
  REP(i, N) {
    cin >> A[i] >> B[i];
  }
  REP(i, N+1) dp0[i] = -1e18;
  REP(i, N+1) dp1[i] = -1e18;
  REP(i, N+1) dp2[i] = -1e18;
  dp0[0] = 0;
  REP(i, N) {
    to(dp0[i+1], dp0[i] + max({M*A[i], B[i], (M-1)*A[i]+B[i]}));
    if (i > 0) {
      to(dp1[i+1], dp0[i] + max(A[i], B[i]));
      to(dp2[i+1], dp0[i]);
    }
    to(dp1[i+1], dp1[i] + max(A[i], B[i]));
    to(dp2[i+1], dp1[i]);
    to(dp2[i+1], dp2[i]);
  }
  long long ans = max({dp0[N], dp1[N], dp2[N]});
  cout << ans << endl;
}
0