結果

問題 No.818 Dinner time
ユーザー FF256grhyFF256grhy
提出日時 2019-04-19 23:04:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,103 bytes
コンパイル時間 1,416 ms
コンパイル使用メモリ 167,608 KB
実行使用メモリ 6,680 KB
最終ジャッジ日時 2023-10-24 11:02:52
合計ジャッジ時間 3,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,648 KB
testcase_01 AC 2 ms
5,648 KB
testcase_02 AC 2 ms
5,648 KB
testcase_03 AC 2 ms
5,648 KB
testcase_04 AC 2 ms
5,648 KB
testcase_05 AC 2 ms
5,648 KB
testcase_06 AC 2 ms
5,648 KB
testcase_07 AC 2 ms
5,648 KB
testcase_08 AC 2 ms
5,648 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,648 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,648 KB
testcase_13 AC 2 ms
5,648 KB
testcase_14 AC 2 ms
5,648 KB
testcase_15 AC 2 ms
5,648 KB
testcase_16 AC 2 ms
5,648 KB
testcase_17 AC 50 ms
6,668 KB
testcase_18 AC 36 ms
6,228 KB
testcase_19 AC 39 ms
6,252 KB
testcase_20 AC 51 ms
6,620 KB
testcase_21 AC 47 ms
6,420 KB
testcase_22 AC 35 ms
6,140 KB
testcase_23 AC 41 ms
6,284 KB
testcase_24 AC 59 ms
6,680 KB
testcase_25 AC 41 ms
6,276 KB
testcase_26 AC 34 ms
6,108 KB
testcase_27 AC 51 ms
6,548 KB
testcase_28 AC 43 ms
6,316 KB
testcase_29 AC 55 ms
6,632 KB
testcase_30 AC 48 ms
6,444 KB
testcase_31 AC 50 ms
6,532 KB
testcase_32 AC 42 ms
6,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

const int M = 100000;

LL n, m, a[M], b[M], s[M + 1], sma[M + 1];

int main() {
	cin >> n >> m;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	inc(i, n) { s[i + 1] = s[i] + max(a[i], b[i]); }
	dec(i, n + 1) { sma[i] = max(s[i], sma[i + 1]); }
	
	LL ans = -1e16, x = 0;
	inc(i, n) {
		x += max(b[i], (m - 1) * a[i] + max(a[i], b[i]));
		setmax(ans, x + sma[i + 1] - s[i + 1]);
	}
	
	cout << ans << endl;
	
	return 0;
}
0