#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long ans = 0;
    for (int i = 1; i < n; i++) {
        int diff = max(0, a[i] + a[i - 1] - x);
        ans += diff;
        a[i] -= diff;
    }

    cout << ans << endl;

    return 0;
}
# 86 T2## 题目描述小 A 有 $n$ 个糖果盒第 $i$ 个盒中有 $a_i$ 颗糖果。小 A 每次可以从其中一盒糖果中吃掉一颗他想知道要让任意两个相邻的盒子中糖的个数之和都不大于 $x$至少得吃掉几颗糖。## 输入格式输入的第一行是两个用空格隔开的整数代表糖果盒的个数 $n$ 和给定的参数 $x$。第二行有 $n$ 个用空格隔开的整数第 $i$ 个整数代表第 $i$ 盒糖的糖果个数 $

原文地址: https://www.cveoy.top/t/topic/iIO8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录