Submission #24251738


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(ll& a : A) cin >> a;
    ll b = A[0], c = 0;
    vector<ll> B = {b, c};
    for(ll i = 1; i < N; i++){
        const ll x = A[i] - A[i - 1];
        if(x >= 0) b += x;
        else c -= x;
        B.push_back(b);
        B.push_back(c);
    }
    auto cen = B.begin() + N;
    nth_element(B.begin(), cen, B.end());
    cout << transform_reduce(B.begin(), B.end(), 0LL, plus<>{}, [&](ll x){ return abs(x - *cen); }) << endl;
}

Submission Info

Submission Time
Task D - Inc, Dec - Decomposition
User tatyam
Language C++ (GCC 9.2.1)
Score 700
Code Size 560 Byte
Status AC
Exec Time 79 ms
Memory 8952 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 8 ms 3500 KiB
01_sample_02.txt AC 3 ms 3480 KiB
01_sample_03.txt AC 2 ms 3504 KiB
02_small_01.txt AC 2 ms 3500 KiB
02_small_02.txt AC 3 ms 3404 KiB
02_small_03.txt AC 2 ms 3556 KiB
02_small_04.txt AC 3 ms 3484 KiB
02_small_05.txt AC 2 ms 3504 KiB
02_small_06.txt AC 4 ms 3480 KiB
02_small_07.txt AC 5 ms 3592 KiB
02_small_08.txt AC 3 ms 3544 KiB
02_small_09.txt AC 2 ms 3476 KiB
02_small_10.txt AC 3 ms 3488 KiB
03_rand_01.txt AC 12 ms 3776 KiB
03_rand_02.txt AC 42 ms 5864 KiB
03_rand_03.txt AC 39 ms 5904 KiB
03_rand_04.txt AC 7 ms 3784 KiB
03_rand_05.txt AC 52 ms 6232 KiB
03_rand_06.txt AC 14 ms 3852 KiB
03_rand_07.txt AC 41 ms 5960 KiB
03_rand_08.txt AC 57 ms 8372 KiB
03_rand_09.txt AC 64 ms 8640 KiB
03_rand_10.txt AC 65 ms 8592 KiB
03_rand_11.txt AC 19 ms 4068 KiB
03_rand_12.txt AC 30 ms 4536 KiB
03_rand_13.txt AC 42 ms 5992 KiB
03_rand_14.txt AC 28 ms 4448 KiB
03_rand_15.txt AC 39 ms 5992 KiB
03_rand_16.txt AC 58 ms 8436 KiB
03_rand_17.txt AC 22 ms 4344 KiB
03_rand_18.txt AC 65 ms 8668 KiB
03_rand_19.txt AC 6 ms 3572 KiB
03_rand_20.txt AC 72 ms 8800 KiB
04_handmade_01.txt AC 76 ms 8844 KiB
04_handmade_02.txt AC 78 ms 8924 KiB
04_handmade_03.txt AC 42 ms 8952 KiB
04_handmade_04.txt AC 72 ms 8916 KiB
04_handmade_05.txt AC 79 ms 8788 KiB
04_handmade_06.txt AC 74 ms 8868 KiB
04_handmade_07.txt AC 69 ms 8812 KiB