#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Candies"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
#define int long long
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
/// if i is a center of an interval, L[i] R[i] is the border, if not, L[i] R[i] point toward the center
int n;
ll a[maxn];
int L[maxn], R[maxn], del[maxn];
void solve()
{
cin >> n;
fi(i, 1, n) {
cin >> a[i];
L[i] = i - 1, R[i] = i + 1;
}
ll ans = 0;
priority_queue<pair<ll, int>> q;
fi(i, 1, n) q.push({a[i], i});
a[0] = a[n + 1] = -1e18;
fi(_, 1, (n + 1) / 2) {
while(del[q.top().second]) q.pop();
ll w, id; tie(w, id) = q.top(); q.pop();
ans += w;
cout << ans << '\n';
del[L[id]] = 1, del[R[id]] = 1;
a[id] = a[L[id]] + a[R[id]] - a[id];
L[id] = L[L[id]];
R[L[id]] = id;
R[id] = R[R[id]];
L[R[id]] = id;
q.push({a[id], id});
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Candies"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
#define int long long
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
/// if i is a center of an interval, L[i] R[i] is the border, if not, L[i] R[i] point toward the center
int n;
ll a[maxn];
int L[maxn], R[maxn], del[maxn];
void solve()
{
cin >> n;
fi(i, 1, n) {
cin >> a[i];
L[i] = i - 1, R[i] = i + 1;
}
ll ans = 0;
priority_queue<pair<ll, int>> q;
fi(i, 1, n) q.push({a[i], i});
a[0] = a[n + 1] = -1e18;
fi(_, 1, (n + 1) / 2) {
while(del[q.top().second]) q.pop();
ll w, id; tie(w, id) = q.top(); q.pop();
ans += w;
cout << ans << '\n';
del[L[id]] = 1, del[R[id]] = 1;
a[id] = a[L[id]] + a[R[id]] - a[id];
L[id] = L[L[id]];
R[L[id]] = id;
R[id] = R[R[id]];
L[R[id]] = id;
q.push({a[id], id});
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
candies.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main()
| ^~~~
candies.cpp:112:10: error: redefinition of 'const long long int mod'
112 | const ll mod = 1e9 + 7; //972663749
| ^~~
candies.cpp:21:10: note: 'const long long int mod' previously defined here
21 | const ll mod = 1e9 + 7; //972663749
| ^~~
candies.cpp:113:10: error: redefinition of 'const long long int base'
113 | const ll base = 911382323;
| ^~~~
candies.cpp:22:10: note: 'const long long int base' previously defined here
22 | const ll base = 911382323;
| ^~~~
candies.cpp:116:5: error: redefinition of 'long long int n'
116 | int n;
| ^
candies.cpp:25:5: note: 'long long int n' previously declared here
25 | int n;
| ^
candies.cpp:117:4: error: redefinition of 'long long int a [200007]'
117 | ll a[maxn];
| ^
candies.cpp:26:4: note: 'long long int a [200007]' previously declared here
26 | ll a[maxn];
| ^
candies.cpp:118:5: error: redefinition of 'long long int L [200007]'
118 | int L[maxn], R[maxn], del[maxn];
| ^
candies.cpp:27:5: note: 'long long int L [200007]' previously declared here
27 | int L[maxn], R[maxn], del[maxn];
| ^
candies.cpp:118:14: error: redefinition of 'long long int R [200007]'
118 | int L[maxn], R[maxn], del[maxn];
| ^
candies.cpp:27:14: note: 'long long int R [200007]' previously declared here
27 | int L[maxn], R[maxn], del[maxn];
| ^
candies.cpp:118:23: error: redefinition of 'long long int del [200007]'
118 | int L[maxn], R[maxn], del[maxn];
| ^~~
candies.cpp:27:23: note: 'long long int del [200007]' previously declared here
27 | int L[maxn], R[maxn], del[maxn];
| ^~~
candies.cpp:120:6: error: redefinition of 'void solve()'
120 | void solve()
| ^~~~~
candies.cpp:29:6: note: 'void solve()' previously defined here
29 | void solve()
| ^~~~~
candies.cpp:158:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
158 | main()
| ^~~~
candies.cpp:158:1: error: redefinition of 'int main()'
candies.cpp:67:1: note: 'int main()' previously defined here
67 | main()
| ^~~~
candies.cpp: In function 'int main()':
candies.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp: In function 'int main()':
candies.cpp:166:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
166 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:167:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
167 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~