Last active
May 8, 2017 14:40
-
-
Save enriquefynn/e07cd68a52181baba6b3ed645d1a32be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <cmath> | |
using namespace std; | |
int main() { | |
long long n, x, v[1000000]; | |
unsigned long long cnt = 0; | |
cin >> n >> x; | |
for (int i = 0; i < n; ++i) | |
cin >> v[i]; | |
for (int i = 0; i < n-1; ++i) { | |
long long rem = v[i] + v[i+1] - x; | |
if (rem < 0) | |
continue; | |
if (rem > v[i+1]) { | |
v[i] = v[i] - (v[i+1] - rem); | |
v[i+1] = 0; | |
cnt += rem; | |
} | |
else { | |
v[i+1] -= rem; | |
cnt += rem; | |
} | |
} | |
cout << cnt << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment