Advertisement
ivangarvanliev

Untitled

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