Language: C++

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
#define int LL
int N, x;
VI a, asum;
VPII pp;    //(num, idx)

signed main(void) {
    scanf("%lld%lld", &N, &x);
    a.resize(N);
    asum.resize(N - 1);
    pp.resize(N);
    for_each(ALL(a), [](int &e){scanf("%lld", &e);});
    int cnt = 0;
    REP(i, N - 1) {
        int sum = a[i] + a[i + 1];
        if (sum <= x) continue;
        int buf = sum - x;
        if (buf <= 0) {
            a[i] = a[i + 1] = 0;
            cnt += buf;
            continue;
        }
        a[i + 1] -= buf;
        cnt += buf;
        if (a[i + 1] < 0) {
            a[i] -= a[i + 1];
        }
    }
    cout << cnt << endl;
}


Compiler output:
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<int*, vector<int> >; _Funct = main()::<lambda(LL&)>]':
a.cc:70:13:   required from here
   70 |     for_each(ALL(a), [](int &e){scanf("%lld", &e);});
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3786:12: error: no match for call to '(main()::<lambda(LL&)>) (int&)'
 3786 |         __f(*__first);
      |         ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:3786:12: note: candidate: 'void (*)(LL&)' {aka 'void (*)(long long int&)'} (conversion)
/usr/include/c++/14/bits/stl_algo.h:3786:12: note:   conversion of argument 2 would be ill-formed:
/usr/include/c++/14/bits/stl_algo.h:3786:12: error: cannot bind non-const lvalue reference of type 'LL&' {aka 'long long int&'} to a value of type 'int'
a.cc:70:22: note: candidate: 'main()::<lambda(LL&)>' (near match)
   70 |     for_each(ALL(a), [](int &e){scanf("%lld", &e);});
      |                      ^
a.cc:70:22: note:   conversion of argument 1 would be ill-formed:
a.cc:70:22: error: cannot bind non-const lvalue reference of type 'LL&' {aka 'long long int&'} to a value of type 'int'