結果

問題 No.818 Dinner time
ユーザー tomatoma
提出日時 2019-04-19 22:16:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,442 bytes
コンパイル時間 4,918 ms
コンパイル使用メモリ 172,808 KB
実行使用メモリ 7,036 KB
最終ジャッジ日時 2023-10-24 03:51:54
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 37 ms
5,452 KB
testcase_23 AC 43 ms
5,980 KB
testcase_24 AC 62 ms
7,036 KB
testcase_25 AC 43 ms
5,980 KB
testcase_26 WA -
testcase_27 AC 54 ms
6,508 KB
testcase_28 AC 44 ms
5,980 KB
testcase_29 AC 58 ms
6,772 KB
testcase_30 AC 49 ms
6,244 KB
testcase_31 AC 53 ms
6,508 KB
testcase_32 AC 43 ms
5,980 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];
	}
	//cout << *max_element(imos.begin(), imos.end()) << endl;

	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 minv = INFL;
	ll maxv = mid.back();
	vector<ll> imos2(N, 0);
	for (int i = N - 2; i >= 0; i--) {
		imos2[i] = maxv - mid[i];
		maxv = max(maxv, mid[i]);
	}

	ll res = abs.front().second;
	REP(i, N - 1)res = max(res, imos[i] + imos2[i]);
	res = max(res, imos.back());
	cout << res << endl;

	return 0;
}
0