結果

問題 No.818 Dinner time
ユーザー pekempeypekempey
提出日時 2019-04-19 22:07:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 72,272 KB
実行使用メモリ 6,852 KB
最終ジャッジ日時 2023-08-20 00:46:30
合計ジャッジ時間 2,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 49 ms
6,852 KB
testcase_18 AC 34 ms
5,352 KB
testcase_19 AC 38 ms
5,476 KB
testcase_20 AC 48 ms
6,468 KB
testcase_21 AC 44 ms
6,156 KB
testcase_22 AC 34 ms
5,136 KB
testcase_23 AC 40 ms
5,732 KB
testcase_24 AC 56 ms
6,672 KB
testcase_25 AC 39 ms
5,356 KB
testcase_26 AC 33 ms
5,208 KB
testcase_27 AC 49 ms
6,164 KB
testcase_28 AC 40 ms
5,616 KB
testcase_29 AC 53 ms
6,684 KB
testcase_30 AC 44 ms
5,984 KB
testcase_31 AC 47 ms
6,168 KB
testcase_32 AC 40 ms
5,704 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