Created
May 27, 2020 19:50
-
-
Save gbrls/de8e08170dc0aa633a78213ed3f27e8f to your computer and use it in GitHub Desktop.
OBI 2014 fase 1 Fechadura
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 <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
int n,m;cin>>n>>m; | |
int arr[n]; | |
for(int i=0;i<n;i++) cin>>arr[i]; | |
int acc=0; | |
for(int i=0;i<n-1;i++) { | |
int mn = arr[i]; | |
if(arr[i]==m) continue; | |
if(mn < m) { | |
arr[i] += m-mn; | |
arr[i+1] += m-mn; | |
acc += m-mn; | |
} else if( mn > m) { | |
arr[i] -= mn-m; | |
arr[i+1] -= mn-m; | |
acc += mn-m; | |
} | |
} | |
cout<<acc<<'\n'; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment