結果

問題 No.818 Dinner time
ユーザー pekempeypekempey
提出日時 2019-04-19 22:07:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 74,044 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-05-07 08:13:51
合計ジャッジ時間 2,397 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 45 ms
6,912 KB
testcase_18 AC 33 ms
5,632 KB
testcase_19 AC 35 ms
5,632 KB
testcase_20 AC 46 ms
6,784 KB
testcase_21 AC 42 ms
6,144 KB
testcase_22 AC 31 ms
5,376 KB
testcase_23 AC 40 ms
5,888 KB
testcase_24 AC 54 ms
7,040 KB
testcase_25 AC 38 ms
5,760 KB
testcase_26 AC 30 ms
5,376 KB
testcase_27 AC 46 ms
6,400 KB
testcase_28 AC 39 ms
5,760 KB
testcase_29 AC 50 ms
6,784 KB
testcase_30 AC 44 ms
6,144 KB
testcase_31 AC 46 ms
6,400 KB
testcase_32 AC 40 ms
5,888 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