first 7 Introductory problems
This commit is contained in:
22
CSES - CSES Problem Set/Increasing_Array.cpp
Normal file
22
CSES - CSES Problem Set/Increasing_Array.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Increasing Array
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
typedef long long ll;
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<ll> array(n);
|
||||
for (auto &e : array) cin >> e;
|
||||
ll count = 0;
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (array[i] < array[i-1]) {
|
||||
count += array[i-1] - array[i];
|
||||
array[i] = array[i-1];
|
||||
}
|
||||
}
|
||||
cout << count << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user