Created
July 20, 2020 10:19
-
-
Save vipul43/b3c08ff433ab6963a4047b7a981eba08 to your computer and use it in GitHub Desktop.
cses day1 problems solutions
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 <fstream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
typedef long long ll; | |
void solution(){ | |
ll n; | |
cin >> n; | |
ll arr[n]; | |
for(ll i=0; i<n; i++){ | |
cin >> arr[i]; | |
} | |
ll turns = 0; | |
for(ll i=0; i<n-1; i++){ | |
if(arr[i]>arr[i+1]){ | |
turns=turns+(arr[i]-arr[i+1]); | |
arr[i+1]=arr[i]; | |
} | |
} | |
cout << turns << endl; | |
} | |
int main() { | |
int T=1; | |
// cin >> T; | |
for(int t=0; t<T; t++) { | |
solution(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment