結果
問題 |
No.818 Dinner time
|
ユーザー |
![]() |
提出日時 | 2019-04-19 21:56:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,097 bytes |
コンパイル時間 | 1,453 ms |
コンパイル使用メモリ | 168,420 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 19:01:59 |
合計ジャッジ時間 | 2,781 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 WA * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; ll N, M; ll A[100050]; ll B[100050]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; for(int i = 1; i <= N; i++) cin >> A[i] >> B[i]; ll ans = 0; ll now = 0; int last = 0; for(int i = 1; i <= N; i++) { now += max(A[i], B[i]); if(ans < now) { ans = max(ans, now); last = i; } } ll ans2 = 0; now = 0; for(int i = 1; i <= N; i++) { if(A[i] >= 0) { now += (M - 1) * A[i]; ans2 = max(ans2, now); continue; } if(B[i] >= 0) { continue; } if(B[i] >= A[i]) { continue; } ll val = max((M - 1) * A[i], B[i]); if(last >= i) val = max(val, B[i] - A[i]); now += val; ans2 = max(ans2, now); } cout << ans + ans2 << endl; return 0; }