Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <exception>
- #include <cmath>
- #include <unordered_set>
- #include <vector>
- #include <unordered_map>
- #include <algorithm>
- using namespace std;
- void cv(vector <int> v) {
- for (int el: v) {
- cout << el << ' ';
- } cout << "\n";
- }
- int n;
- vector <int> a;
- int l(int R) {
- cout << "R: " << R <<"\n";
- if (R == 0 || R == n - 1){
- return 0;
- }
- auto max_it = max_element(a.begin(), a.begin() + R - 1);
- int mxi = R - (abs(distance(a.begin() + R, max_it)));
- cout << "mxi: " << mxi << "\n";
- cout << "dst: " << abs(distance(a.begin() + R, max_it)) << "\n";
- int s = 0;
- int h = a[mxi];
- cout << "h: " << h << "\n";
- for (int i = R - 1; i >= mxi; --i) {
- if (h < a[i]) {
- continue;
- }
- cout << "i: " << i << "\n";
- s += h - a[i];
- }
- cout << "s: " << s << "\n";
- cout << "\n";
- int add = l(mxi);
- return s + add;
- }
- int r(int L) {
- cout << "L: " << L << "\n";
- if (L == n - 1 || L == 0) {
- return 0;
- }
- auto max_it = max_element(a.begin() + L + 1, a.end());
- int mxi = L + abs(distance(a.begin() + L, max_it));
- cout << "mxi: " << mxi << "\n";
- cout << "dst: " << abs(distance(a.begin() + L, max_it)) << "\n";
- int s = 0;
- int h = a[mxi];
- cout << "h: " << h << "\n";
- for (int i = L + 1; i <= mxi; ++i) {
- if (h < a[i]) {
- continue;
- }
- cout << "i: " << i << "\n";
- s += h - a[i];
- }
- cout << "s: " << s << "\n";
- cout << "\n";
- int add = r(mxi);
- return s + add;
- }
- /*
- 10
- 7 0 4 2 5 0 6 4 0 5
- 16
- 1 2 4 0 0 5 4 2 6 8 2 3 4 5 5 3
- */
- int main() {
- cin >> n;
- a.resize(n);
- for (int &el: a) cin >> el;
- auto max_it = max_element(a.begin(), a.end());
- int mxi = distance(a.begin(), max_it);
- int s = l(mxi) + r(mxi);
- cout << s << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement