commit 510f47d04834a64ab96c4c2de46df41accf89ee2 parent 88bd7c201885fcbf6ce3a1d9ba959294ef85f75f Author: superpozycja <anna@superpozycja.net> Date: Wed, 23 Oct 2024 21:36:34 +0200 solve increasing array Diffstat:
A | intro/increasing_array.cpp | | | 26 | ++++++++++++++++++++++++++ |
1 file changed, 26 insertions(+), 0 deletions(-)
diff --git a/intro/increasing_array.cpp b/intro/increasing_array.cpp @@ -0,0 +1,26 @@ +#include <bits/stdc++.h> + +using namespace std; + +void solve() +{ + long n, prev, res = 0; + + cin >> n; + cin >> prev; + + for (int i = 1; i < n; i++) { + int a; + + cin >> a; + res += prev - a > 0 ? prev - a : 0; + a += prev - a > 0 ? prev - a : 0; + prev = a; + } + cout << res << "\n"; +} + +int main() +{ + solve(); +}