結果
| 問題 | No.818 Dinner time |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-22 20:13:48 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 874 bytes |
| 記録 | |
| コンパイル時間 | 649 ms |
| コンパイル使用メモリ | 76,764 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-02-23 11:37:35 |
| 合計ジャッジ時間 | 2,392 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;
const int N = 100010;
const LL NINF = -1e18;
PLL p[N];
int n, m;
LL dp[N][2], ans;
int main() {
// freopen("dinner.in", "r", stdin);
// freopen("dinner.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld", &p[i].first, &p[i].second);
}
dp[1][0] = max(max(p[1].first * m, p[1].second), p[1].first * (m - 1) + p[1].second);
dp[1][1] = NINF;
ans = dp[1][0];
for (int i = 2; i <= n; ++i) {
dp[i][0] = dp[i - 1][0] + max(max(p[i].first * m, p[i].second), p[i].first * (m - 1) + p[i].second);
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + max(p[i].first, p[i].second);
ans = max(max(ans, dp[i][0]), dp[i][1]);
}
printf("%lld\n", ans);
return 0;
}