-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncreasingArray.cpp
More file actions
51 lines (40 loc) · 1.11 KB
/
Copy pathIncreasingArray.cpp
File metadata and controls
51 lines (40 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
#define int long long
#define ln "\n"
#define fastio ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define mod 1e9 + 7
#define rep(i, n) for (long long i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
void solve()
{
// rep(i, 9) cout << (int)(1000000000-1)*i << ln;
int n;
cin>>n;
vector<int> v(n);
rep(i, n) cin>>v[i];
int cnt=0;
for(int i=1; i<n; i++){
// start from index 1 and just check if the current
// element is smaller than previous
if(v[i]<v[i-1]) {
// if so then just increment this current element
// upto same as previous element. (for min count)
cnt += v[i-1]-v[i];
// debug(cnt);
// make current element equal to previous element
v[i] = v[i-1];
}
}
cout << cnt;
}
int32_t main()
{
// fastio;
int t=1;
// cin>>t;
while (t--)
solve();
return 0;
}