Submission #3025160


Source Code Expand

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n;
ll c;
ll x[MAXN];
ll y[MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> c;
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
	}
	ll ans = 0;
	ll sum = accumulate(y, y + n, 0ll);
	ll mx = 0;
	ll mx2 = 0;
	ll asum = 0;
	for (int i = n - 1; i >= 0; --i) {
		ans = max(ans, sum - x[i] + mx2);
		ans = max(ans, sum - 2 * x[i] + mx);
		sum -= y[i];
		asum += y[i];
		mx = max(mx, asum - (c - x[i]));
		mx2 = max(mx2, asum - 2 * (c - x[i]));
	}
	ans = max(ans, mx);
	cout << ans << "\n";
	return 0;
}


Submission Info

Submission Time
Task D - Static Sushi
User LHiC
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1156 Byte
Status AC
Exec Time 25 ms
Memory 1792 KB

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 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
a04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 1 ms 256 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 256 KB
b13 AC 1 ms 256 KB
b14 AC 1 ms 256 KB
b15 AC 1 ms 256 KB
b16 AC 1 ms 256 KB
b17 AC 1 ms 256 KB
b18 AC 1 ms 256 KB
b19 AC 1 ms 256 KB
b20 AC 1 ms 256 KB
b21 AC 1 ms 256 KB
b22 AC 2 ms 384 KB
b23 AC 1 ms 256 KB
b24 AC 1 ms 256 KB
b25 AC 1 ms 256 KB
b26 AC 1 ms 256 KB
b27 AC 1 ms 256 KB
b28 AC 1 ms 256 KB
b29 AC 1 ms 256 KB
c30 AC 15 ms 1792 KB
c31 AC 19 ms 1792 KB
c32 AC 24 ms 1792 KB
c33 AC 24 ms 1792 KB
c34 AC 25 ms 1792 KB
c35 AC 14 ms 1792 KB
c36 AC 23 ms 1792 KB
c37 AC 23 ms 1792 KB
c38 AC 23 ms 1792 KB
c39 AC 23 ms 1792 KB
c40 AC 23 ms 1792 KB
c41 AC 22 ms 1792 KB
c42 AC 22 ms 1792 KB
c43 AC 3 ms 384 KB
c44 AC 22 ms 1792 KB
c45 AC 1 ms 256 KB
c46 AC 22 ms 1792 KB
c47 AC 1 ms 256 KB
c48 AC 23 ms 1792 KB
c49 AC 22 ms 1792 KB
c50 AC 23 ms 1792 KB