cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

increasing_array.cpp (306B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 void solve()
      6 {
      7 	long n, prev, res = 0;
      8 
      9 	cin >> n;
     10 	cin >> prev;
     11 
     12 	for (int i = 1; i < n; i++) {
     13 		int a;
     14 
     15 		cin >> a;
     16 		res += prev - a > 0 ? prev - a : 0;
     17 		a += prev - a > 0 ? prev - a : 0;
     18 		prev = a;
     19 	}
     20 	cout << res << "\n";
     21 }
     22 
     23 int main()
     24 {
     25 	solve();
     26 }