Submission #1606387


Source Code Expand

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

ll x, n, q, i;
ll r[maxN];
ll tm, ini, a, b, c;

ll act_tm, nxt, dif;

void decrease_with(ll dif) {
    ll aux = min(c, dif);

    c -= aux;
    dif -= aux;
    if (dif == 0) return;

    if (b - a <= dif) {
        a = b = 0;
        return;
    }

    a += dif;
}

void increase_with(ll dif) {
    ll aux = min(x - (c + b - a), dif);

    c += aux;
    dif -= aux;
    if (dif == 0) return;

    if (b - a <= dif) {
        a = b = 0;
        c = x;
        return;
    }

    b -= dif;
    c += dif;
}

int main()
{
  // freopen("test.in","r",stdin);

    cin >> x >> n;
    for (i = 1; i <= n; i++) cin >> r[i];
    r[n + 1] = 1000000001;

    a = 0; b = x; c = 0;
    act_tm = 0; nxt = 1;

    cin >> q;
    for (i = 1; i <= q; i++) {
        cin >> tm >> ini;

        while (act_tm != tm) {
            if (tm < r[nxt]) {
                dif = tm - act_tm;
                if (nxt % 2 == 1)
                    decrease_with(dif);
                else
                    increase_with(dif);

                act_tm = tm;
            } else {
                dif = r[nxt] - act_tm;
                if (nxt % 2 == 1)
                    decrease_with(dif);
                else
                    increase_with(dif);

                act_tm = r[nxt];
                nxt++;
            }
        }

        if (ini <= a) {
            cout << c << '\n';
            continue;
        }

        if (ini >= b) {
            cout << c + b - a << '\n';
            continue;
        }

        cout << c + ini - a << '\n';
    }


    return 0;
}

Submission Info

Submission Time
Task F - Sandglass
User atatomir
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1877 Byte
Status AC
Exec Time 286 ms
Memory 2048 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 236 ms 1280 KB
1_004.txt AC 251 ms 1280 KB
1_005.txt AC 258 ms 1280 KB
1_006.txt AC 242 ms 1280 KB
1_007.txt AC 248 ms 1280 KB
1_008.txt AC 261 ms 1280 KB
1_009.txt AC 247 ms 1280 KB
1_010.txt AC 252 ms 1280 KB
1_011.txt AC 268 ms 1280 KB
1_012.txt AC 246 ms 1408 KB
1_013.txt AC 252 ms 1408 KB
1_014.txt AC 266 ms 1408 KB
1_015.txt AC 246 ms 1536 KB
1_016.txt AC 256 ms 1536 KB
1_017.txt AC 271 ms 1408 KB
1_018.txt AC 249 ms 1536 KB
1_019.txt AC 264 ms 1536 KB
1_020.txt AC 274 ms 1536 KB
1_021.txt AC 253 ms 1536 KB
1_022.txt AC 262 ms 1664 KB
1_023.txt AC 277 ms 1664 KB
1_024.txt AC 261 ms 1536 KB
1_025.txt AC 266 ms 1792 KB
1_026.txt AC 286 ms 1792 KB
1_027.txt AC 267 ms 1536 KB
1_028.txt AC 272 ms 1664 KB
1_029.txt AC 284 ms 1920 KB
1_030.txt AC 273 ms 1664 KB
1_031.txt AC 280 ms 1664 KB
1_032.txt AC 286 ms 2048 KB
1_033.txt AC 232 ms 1024 KB
1_034.txt AC 235 ms 1024 KB
1_035.txt AC 272 ms 1792 KB
1_036.txt AC 240 ms 1152 KB
1_037.txt AC 244 ms 1152 KB
1_038.txt AC 279 ms 1920 KB
1_039.txt AC 246 ms 896 KB
1_040.txt AC 244 ms 1280 KB
1_041.txt AC 284 ms 2048 KB