Submission #2544646


Source Code Expand

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

vector<ll> X;
vector<ll> V;
vector<ll> S;
vector<ll> pmax;
vector<ll> nmax;
ll n;
ll c;
int main() {
    cin >> n >> c;
    X.resize(n+1, 0);
    V.resize(n+1, 0);
    S.resize(n+1, 0);
    pmax.resize(n+1, 0);
    nmax.resize(n+1, 0);
    llrep(i, 0, n) {
        cin >> X[i+1] >> V[i+1];
    }

    ll ans = 0;
    llrep(i, 0, n) {
        S[i+1] = S[i] + V[i+1];
        ans = max(ans, S[i+1]-X[i+1]);
    }

    llrep(i, 0, n) {
        if ((S[pmax[i]] - X[pmax[i]]) < (S[i+1] - X[i+1])) {
            pmax[i+1] = i + 1;
        }else{
            pmax[i+1] = pmax[i];
        };

        if ((S[nmax[i]] - 2 * X[nmax[i]]) < (S[i+1] - 2 * X[i+1])) {
            nmax[i+1] = i + 1;
        }else{
            nmax[i+1] = nmax[i];
        };
    }
    llrrep(i, n, 0) {
        ans = max(ans, S[pmax[i-1]] + (S[n] - S[i-1]) - (X[pmax[i-1]] + 2 * (c - X[i])));
        ans = max(ans, S[nmax[i-1]] + (S[n] - S[i-1]) - (X[nmax[i-1]] * 2 + (c - X[i])));
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - Static Sushi
User pshiko
Language C++14 (Clang 3.8.0)
Score 500
Code Size 1950 Byte
Status AC
Exec Time 256 ms
Memory 4224 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 1 ms 256 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 125 ms 4224 KB
c31 AC 188 ms 4224 KB
c32 AC 256 ms 4224 KB
c33 AC 253 ms 4224 KB
c34 AC 254 ms 4224 KB
c35 AC 125 ms 4224 KB
c36 AC 250 ms 4224 KB
c37 AC 246 ms 4224 KB
c38 AC 247 ms 4224 KB
c39 AC 249 ms 4224 KB
c40 AC 251 ms 4224 KB
c41 AC 245 ms 4224 KB
c42 AC 246 ms 4224 KB
c43 AC 25 ms 640 KB
c44 AC 246 ms 4224 KB
c45 AC 4 ms 256 KB
c46 AC 242 ms 4224 KB
c47 AC 1 ms 256 KB
c48 AC 246 ms 4224 KB
c49 AC 248 ms 4224 KB
c50 AC 250 ms 4224 KB