結果
| 問題 | No.818 Dinner time |
| コンテスト | |
| ユーザー |
chocopuu
|
| 提出日時 | 2019-04-19 23:16:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,257 bytes |
| 記録 | |
| コンパイル時間 | 1,632 ms |
| コンパイル使用メモリ | 169,368 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-23 04:50:52 |
| 合計ジャッジ時間 | 3,483 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
const long long MOD = 1e9 + 7, INF = 1e18;
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
signed main()
{
int N, M;
cin >> N >> M;
vector<int> a(N), b(N);
int last = 0, best = 0, dis = 0, sum = 0;
vector<int> lastmax(N + 1, -INF), bestmax(N + 1, -INF), dismax(N + 1, -INF);
lastmax[0] = bestmax[0] = 0;
for (int i = 0; i < N; i++)
{
cin >> a[i] >> b[i];
last += max(a[i], b[i]);
best += a[i];
sum += a[i];
chmax(lastmax[i + 1], last);
chmax(lastmax[i + 1], lastmax[i]);
chmax(bestmax[i + 1], best);
chmax(bestmax[i + 1], bestmax[i]);
}
dis = sum;
rrep(i, 0, N)
{
dis += max(a[i], b[i]);
dis -= a[i];
chmax(dismax[i], dis);
}
int ans = dismax[0];
dismax[N] = bestmax[N];
for (int i = 1; i < N + 1; i++)
{
chmax(ans, dismax[i] + bestmax[i] * (M - 2) + lastmax[i]);
}
cout << ans << endl;
}
chocopuu