結果

問題 No.818 Dinner time
ユーザー tomatoma
提出日時 2019-04-19 22:20:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 169,988 KB
実行使用メモリ 6,804 KB
最終ジャッジ日時 2023-08-20 00:47:04
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 50 ms
6,800 KB
testcase_18 AC 35 ms
5,632 KB
testcase_19 AC 38 ms
5,356 KB
testcase_20 AC 49 ms
6,540 KB
testcase_21 AC 45 ms
6,000 KB
testcase_22 AC 35 ms
5,084 KB
testcase_23 AC 40 ms
5,636 KB
testcase_24 AC 57 ms
6,804 KB
testcase_25 AC 39 ms
5,376 KB
testcase_26 AC 34 ms
5,144 KB
testcase_27 AC 49 ms
6,168 KB
testcase_28 AC 41 ms
5,668 KB
testcase_29 AC 54 ms
6,432 KB
testcase_30 AC 46 ms
5,928 KB
testcase_31 AC 50 ms
6,204 KB
testcase_32 AC 41 ms
5,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll>> abs(N);
	REP(i, N) {
		ll a, b;
		cin >> a >> b;
		abs[i] = { a,b };
	}

	vector<ll> imos(N);
	// collection border
	REP(i, N) {
		auto ab = abs[i];
		ll a = ab.first;
		ll b = ab.second;
		if (a < 0 && b < 0) {
			if (a*M < b)imos[i] = b;
			else imos[i] = a * M;
		}
		else if (a >= 0 && b < 0) {
			imos[i] = a * M;
		}
		else if (a < 0 && b >= 0) {
			imos[i] = b;
		}
		else {
			imos[i] = a * (M - 1) + max(a, b);
		}
	}
	REP(i, N - 1)imos[i + 1] += imos[i];

	vector<ll> mid(N);
	REP(i, N)mid[i] = max(abs[i].first, abs[i].second);
	REP(i, N - 1)mid[i + 1] += mid[i];

	ll maxv = mid.back();
	vector<ll> imos2(N, 0);
	for (int i = N - 2; i >= 0; i--) {
		maxv = max(maxv, mid[i]);
		imos2[i] = maxv - mid[i];
	}

	ll res = -INFL;;
	REP(i, N)res = max(res, imos[i] + imos2[i]);
	cout << res << endl;

	return 0;
}
0