Skip to content

Instantly share code, notes, and snippets.

@vipul43
Created July 20, 2020 10:19
Show Gist options
  • Save vipul43/b3c08ff433ab6963a4047b7a981eba08 to your computer and use it in GitHub Desktop.
Save vipul43/b3c08ff433ab6963a4047b7a981eba08 to your computer and use it in GitHub Desktop.
cses day1 problems solutions
#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