Submission #7691748


Source Code Expand

#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
ll C, x[100000], v[100000];
ll best[100000 + 10];

const ll INF = 1145141919810893;

int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++)cin >> x[i] >> v[i], best[i] = INF;

	ll ans = 0;
	{
		//反時計回りを事前計算して、時計回り方向の区間の終端を全探索
		ll eiyou = 0;
		best[N] = 0;//反時計回り方向で何も食べに行かない
		for (int i = N - 1; i >= 0; i--) {
			eiyou += v[i];
			ll cost = eiyou - C + x[i];
			best[i] = max(best[i + 1], cost);
		}

		eiyou = 0;
		for (int i = 0; i < N; i++) {
			ll tmp = 0;
			eiyou += v[i];
			tmp = eiyou - x[i];
			ans = max(ans, tmp);

			tmp -= x[i];
			tmp += best[i + 1];
			ans = max(ans, tmp);
		}
	}
	
	{

		//時計回りを事前計算して、反時計回り方向の区間の終端を全探索
		ll eiyou = 0;
		best[0] = 0;
		for (int i = 1; i <= N; i++) {
			eiyou += v[i - 1];
			ll cost = eiyou - x[i - 1];
			best[i] = max(best[i - 1], cost);
		}

		eiyou = 0;
		for (int i = N - 1; i >= 0; i--) {
			ll tmp = 0;
			eiyou += v[i];
			tmp = eiyou - (C - x[i]);
			ans = max(ans, tmp);

			tmp -= (C - x[i]);
			tmp += best[i];
			ans = max(ans, tmp);
		}
	}
	
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task D - Static Sushi
User Sen
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1356 Byte
Status AC
Exec Time 98 ms
Memory 2560 KiB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 300 / 300 200 / 200
Status
AC × 4
AC × 29
AC × 50
Set Name Test Cases
Sample a01, a02, a03, a04
Subtask1 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29
Subtask2 a01, a02, a03, a04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, c40, c41, c42, c43, c44, c45, c46, c47, c48, c49, c50
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KiB
a02 AC 1 ms 256 KiB
a03 AC 1 ms 256 KiB
a04 AC 1 ms 256 KiB
b05 AC 1 ms 256 KiB
b06 AC 1 ms 256 KiB
b07 AC 1 ms 256 KiB
b08 AC 1 ms 256 KiB
b09 AC 1 ms 256 KiB
b10 AC 1 ms 256 KiB
b11 AC 1 ms 256 KiB
b12 AC 1 ms 256 KiB
b13 AC 1 ms 256 KiB
b14 AC 1 ms 256 KiB
b15 AC 1 ms 256 KiB
b16 AC 1 ms 256 KiB
b17 AC 1 ms 256 KiB
b18 AC 1 ms 256 KiB
b19 AC 1 ms 256 KiB
b20 AC 1 ms 256 KiB
b21 AC 1 ms 256 KiB
b22 AC 1 ms 256 KiB
b23 AC 1 ms 256 KiB
b24 AC 1 ms 256 KiB
b25 AC 1 ms 256 KiB
b26 AC 1 ms 256 KiB
b27 AC 1 ms 256 KiB
b28 AC 1 ms 256 KiB
b29 AC 1 ms 256 KiB
c30 AC 45 ms 2560 KiB
c31 AC 71 ms 2560 KiB
c32 AC 98 ms 2560 KiB
c33 AC 98 ms 2560 KiB
c34 AC 98 ms 2560 KiB
c35 AC 46 ms 2560 KiB
c36 AC 94 ms 2560 KiB
c37 AC 90 ms 2560 KiB
c38 AC 90 ms 2560 KiB
c39 AC 92 ms 2560 KiB
c40 AC 92 ms 2560 KiB
c41 AC 89 ms 2560 KiB
c42 AC 90 ms 2560 KiB
c43 AC 10 ms 512 KiB
c44 AC 90 ms 2560 KiB
c45 AC 2 ms 256 KiB
c46 AC 89 ms 2560 KiB
c47 AC 1 ms 256 KiB
c48 AC 90 ms 2560 KiB
c49 AC 90 ms 2560 KiB
c50 AC 91 ms 2560 KiB