Language: C++

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
// #define range(i,a,b,c) for(int i=a;\
c>0?i<b:\
i>b;\
i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

int H, W;

bool ng(int y, int x) {
	return y < 0 || H <= y || x < 0 || W <= x;
}

// segment tree of min
struct RMQ {
	int n;
	ll d[262244];	// caution : 2^x
	void init(int nmin) {
		for (n = 1; n < nmin; n *= 2);
		memset(d, INF, 2 * n);
	}
	void update(int i, ll x) {
		d[n + i] = x;
		for (int k = (n + i) / 2; k > 0; k >>= 1)
			d[k] = min(d[k * 2], d[k * 2 + 1]);
	}
	int get(int l, int r) const {
		ll m = INF;
		for (; l && l + (l&-l) <= r; l += l&-l)
			m = min(m, d[(n + l) / (l&-l)]);
		for (; l < r; r -= r&-r)
			m = min(m, d[(n + r) / (r&-r) - 1]);
		return m;
	}
};

RMQ rmq;

ll n, m;
vector<ll> a;

struct Mountain_priority_num {
	int num, id;
	bool operator < (const Mountain_priority_num& r) const {
		if (num != r.num) return num < r.num;
		return id > r.id;
	}
}; 

struct Mountain_priority_id {
	int num, id;
	bool operator < (const Mountain_priority_id r) const {

	}
};

void solve() {
	cin >> n;
	a.resize(n);
	rmq.init(n + 10000);
	set<Mountain_priority_num> set1;
	map<int, int> res;
	rep(i, n) {
		cin >> a[i];
		rmq.update(i, INFL-a[i]);
		set1.insert({a[i], i});
	}
	
	while (not set1.empty()) {
		auto max_n_mountain = *set1.rbegin();
		set1.erase(max_n_mountain);

		ll a = rmq.get(0, max_n_mountain.id);
		ll b = rmq.get(max_n_mountain.id + 1, n);
		ll c = max(a, b);
		ll d = max_n_mountain.num - c;
		if (a < b) {
			// 1
			max_n_mountain.num -= d;
			rmq.update(max_n_mountain.id, max_n_mountain + d);
			res[max_n_mountain.id] += d;

			// 2
		}
	}
}

a

























signed main() {
	int T = 100;
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Compiler output:
a.cc: In member function 'bool Mountain_priority_id::operator<(Mountain_priority_id) const':
a.cc:99:9: warning: no return statement in function returning non-void [-Wreturn-type]
   99 |         }
      |         ^
a.cc: In function 'void solve()':
a.cc:111:28: warning: narrowing conversion of 'a.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)i))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
  111 |                 set1.insert({a[i], i});
      |                 ~~~~~~~~~~~^~~~~~~~~~~
a.cc:125:70: error: no match for 'operator+' (operand types are 'Mountain_priority_num' and 'll' {aka 'long long int'})
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                       ~~~~~~~~~~~~~~ ^ ~
      |                                                       |                |
      |                                                       |                ll {aka long long int}
      |                                                       Mountain_priority_num
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'll' {aka 'long long int'}
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'll' {aka 'long long int'}
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   mismatched types 'const _CharT*' and 'Mountain_priority_num'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'll' {aka 'long long int'}
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   'Mountain_priority_num' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:125:72: note:   mismatched types 'const _CharT*' and 'Mountain_priority_num'
  125 |                         rmq.update(max_n_mountain.id, max_n_mountain + d);
      |                                                                        ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3726 |     operator+(_CharT __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3726:5: note:   template argument deduction/substitution failed:
a.cc:125:72: no