You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
260 B
20 lines
260 B
3 years ago
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
int main() {
|
||
|
int n;
|
||
|
cin >> n;
|
||
|
int px = 0;
|
||
|
long long ans = 0;
|
||
|
for (int i = 0; i < n; i++) {
|
||
|
int x;
|
||
|
cin >> x;
|
||
|
if (x < px) {
|
||
|
ans += px - x;
|
||
|
x = px;
|
||
|
}
|
||
|
px = x;
|
||
|
}
|
||
|
cout << ans;
|
||
|
}
|