Advertisement
coloriot

HA_42_1

Feb 16th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class AcidEqualizer {
  6. public:
  7.     void solve() {
  8.         int n;
  9.         cin >> n;
  10.         vector<long long> a(n);
  11.         for (int i = 0; i < n; ++i) {
  12.             cin >> a[i];
  13.         }
  14.    
  15.         for (int i = 1; i < n; ++i) {
  16.             if (a[i] < a[i - 1]) {
  17.                 cout << -1;
  18.                 return;
  19.             }
  20.         }
  21.        
  22.         cout << a[n - 1] - a[0];
  23.     }
  24. };
  25.  
  26. int main(){
  27.     ios::sync_with_stdio(false);
  28.     cin.tie(nullptr);
  29.    
  30.     AcidEqualizer solver;
  31.     solver.solve();
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement