結果

問題 No.818 Dinner time
ユーザー 👑 emthrmemthrm
提出日時 2019-04-20 00:44:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,467 bytes
コンパイル時間 1,141 ms
コンパイル使用メモリ 124,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 00:53:00
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 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,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 16 ms
4,380 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 AC 12 ms
4,376 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 19 ms
4,376 KB
testcase_25 AC 14 ms
4,380 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 18 ms
4,380 KB
testcase_28 AC 14 ms
4,380 KB
testcase_29 AC 19 ms
4,376 KB
testcase_30 AC 16 ms
4,376 KB
testcase_31 AC 17 ms
4,380 KB
testcase_32 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; long long m; cin >> n >> m;
  vector<int> a(n), b(n); REP(i, n) cin >> a[i] >> b[i];
  // K = 0 は invalid
  long long dp_1 = -INF, dp_m = max(a[0] * (m - 1) + max(a[0], b[0]),  (long long)b[0]);
  long long ans = max(dp_1, dp_m);
  FOR(i, 1, n) {
    long long ikkai = max(dp_1, dp_m) + max(a[i], b[i]);
    long long mkai = dp_m + max(a[i] * (m - 1) + max(a[i], b[i]),  (long long)b[i]);
    ans = max({ans, ikkai, mkai});
    dp_1 = ikkai;
    dp_m = mkai;
  }
  cout << ans << '\n';
  return 0;
}
0