#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, a[N], b[N], s, u, v, d[N][4], dp[N][4];
vector<pll> adj[N];
vector<ll> kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void dij(ll ui, ll id)
{
for(int i = 1; i <= n; i ++)d[i][id] = mod;
priority_queue< pll, vector<pll>, greater<pll> > pq;
pq.push({0, ui});
d[ui][id] = 0;
while(!pq.empty())
{
pll u = pq.top();
pq.pop();
if(u.fi != d[u.se][id])continue;
for(pll v : adj[u.se])
{
if(d[v.se][id] > u.fi + v.fi)
{
d[v.se][id] = u.fi + v.fi;
pq.push({d[v.se][id], v.se});
}
}
}
}
void sol()
{
cin >> n;
set<pll> st;
set<ll> id;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
st.insert({a[i], i});
id.insert(i);
}
a[0] = a[n+1] = -mod;
id.insert(0);
id.insert(n+1);
for(int i = 1; i <= (n+1)/2; i ++)
{
pll x = (*st.rbegin());
ans += x.fi;
st.erase(x);
id.erase(x.se);
auto lf = id.lower_bound(x.se);
auto rt = id.upper_bound(x.se);
--lf;
ll l = *lf, r = *rt;
id.erase(r);
st.erase({a[l], l});
st.erase({a[r], r});
a[l] += a[r] - x.fi;
st.insert({a[l], l});
cout << ans << '\n';
}
}
int main()
{
if(fopen(task".INP", "r"))
{
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
5 1
1 2
2 3
3 4
4 5
*/
Compilation message
candies.cpp: In function 'int main()':
candies.cpp:85:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:86:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5196 KB |
Output is correct |
2 |
Correct |
6 ms |
5288 KB |
Output is correct |
3 |
Correct |
5 ms |
5196 KB |
Output is correct |
4 |
Correct |
5 ms |
5288 KB |
Output is correct |
5 |
Correct |
5 ms |
5196 KB |
Output is correct |
6 |
Correct |
7 ms |
5196 KB |
Output is correct |
7 |
Correct |
5 ms |
5196 KB |
Output is correct |
8 |
Correct |
6 ms |
5196 KB |
Output is correct |
9 |
Correct |
5 ms |
5196 KB |
Output is correct |
10 |
Correct |
5 ms |
5292 KB |
Output is correct |
11 |
Correct |
5 ms |
5196 KB |
Output is correct |
12 |
Correct |
5 ms |
5288 KB |
Output is correct |
13 |
Correct |
5 ms |
5276 KB |
Output is correct |
14 |
Correct |
6 ms |
5196 KB |
Output is correct |
15 |
Correct |
5 ms |
5196 KB |
Output is correct |
16 |
Correct |
5 ms |
5196 KB |
Output is correct |
17 |
Correct |
7 ms |
5196 KB |
Output is correct |
18 |
Correct |
5 ms |
5292 KB |
Output is correct |
19 |
Correct |
5 ms |
5196 KB |
Output is correct |
20 |
Correct |
5 ms |
5288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5196 KB |
Output is correct |
2 |
Correct |
6 ms |
5288 KB |
Output is correct |
3 |
Correct |
5 ms |
5196 KB |
Output is correct |
4 |
Correct |
5 ms |
5288 KB |
Output is correct |
5 |
Correct |
5 ms |
5196 KB |
Output is correct |
6 |
Correct |
7 ms |
5196 KB |
Output is correct |
7 |
Correct |
5 ms |
5196 KB |
Output is correct |
8 |
Correct |
6 ms |
5196 KB |
Output is correct |
9 |
Correct |
5 ms |
5196 KB |
Output is correct |
10 |
Correct |
5 ms |
5292 KB |
Output is correct |
11 |
Correct |
5 ms |
5196 KB |
Output is correct |
12 |
Correct |
5 ms |
5288 KB |
Output is correct |
13 |
Correct |
5 ms |
5276 KB |
Output is correct |
14 |
Correct |
6 ms |
5196 KB |
Output is correct |
15 |
Correct |
5 ms |
5196 KB |
Output is correct |
16 |
Correct |
5 ms |
5196 KB |
Output is correct |
17 |
Correct |
7 ms |
5196 KB |
Output is correct |
18 |
Correct |
5 ms |
5292 KB |
Output is correct |
19 |
Correct |
5 ms |
5196 KB |
Output is correct |
20 |
Correct |
5 ms |
5288 KB |
Output is correct |
21 |
Correct |
615 ms |
31828 KB |
Output is correct |
22 |
Correct |
628 ms |
31920 KB |
Output is correct |
23 |
Correct |
571 ms |
31864 KB |
Output is correct |
24 |
Correct |
269 ms |
31644 KB |
Output is correct |
25 |
Correct |
275 ms |
31696 KB |
Output is correct |
26 |
Correct |
282 ms |
31796 KB |
Output is correct |
27 |
Correct |
296 ms |
32016 KB |
Output is correct |
28 |
Correct |
299 ms |
31856 KB |
Output is correct |
29 |
Correct |
293 ms |
31864 KB |
Output is correct |
30 |
Correct |
307 ms |
31904 KB |
Output is correct |
31 |
Correct |
318 ms |
31996 KB |
Output is correct |
32 |
Correct |
310 ms |
31812 KB |
Output is correct |
33 |
Correct |
416 ms |
31656 KB |
Output is correct |
34 |
Correct |
421 ms |
31704 KB |
Output is correct |
35 |
Correct |
422 ms |
31732 KB |
Output is correct |
36 |
Correct |
615 ms |
31852 KB |
Output is correct |
37 |
Correct |
565 ms |
31812 KB |
Output is correct |
38 |
Correct |
639 ms |
31808 KB |
Output is correct |
39 |
Correct |
270 ms |
31744 KB |
Output is correct |
40 |
Correct |
273 ms |
31644 KB |
Output is correct |
41 |
Correct |
267 ms |
31712 KB |
Output is correct |
42 |
Correct |
297 ms |
31904 KB |
Output is correct |
43 |
Correct |
292 ms |
31852 KB |
Output is correct |
44 |
Correct |
295 ms |
31888 KB |
Output is correct |
45 |
Correct |
305 ms |
31812 KB |
Output is correct |
46 |
Correct |
311 ms |
31808 KB |
Output is correct |
47 |
Correct |
303 ms |
31864 KB |
Output is correct |
48 |
Correct |
429 ms |
31684 KB |
Output is correct |
49 |
Correct |
434 ms |
31824 KB |
Output is correct |
50 |
Correct |
411 ms |
31628 KB |
Output is correct |