Advertisement
ivangarvanliev

Untitled

Jun 3rd, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int arr [n];
  10.     for (int i = 0; i < n; ++i) {
  11.         cin >> arr[i];
  12.     }
  13.    
  14.     long long moves = 0;
  15.     for (int i = 1; i < n; ++i) {
  16.         if (arr[i] < arr[i - 1]) {
  17.             moves += arr[i - 1] - arr[i];
  18.             arr[i] = arr[i - 1];
  19.         }
  20.     }
  21.    
  22.     cout << moves << endl;
  23.    
  24.     return 0;
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement