Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class AcidEqualizer {
- public:
- void solve() {
- int n;
- cin >> n;
- vector<long long> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- for (int i = 1; i < n; ++i) {
- if (a[i] < a[i - 1]) {
- cout << -1;
- return;
- }
- }
- cout << a[n - 1] - a[0];
- }
- };
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- AcidEqualizer solver;
- solver.solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement