Submission #1098620

# Submission time Handle Problem Language Result Execution time Memory
1098620 2024-10-09T16:11:49 Z flyingkite Candies (JOI18_candies) C++17
100 / 100
106 ms 14184 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()
 
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll a[N], prv[N], nxt[N], del[N], ans[N];
ll n;
struct cmp{
	bool operator()(const pll &a, const pll &b){
		return a.S < b.S;
	}
};
void to_thic_cau(){ 
	cin >> n;
	priority_queue<pll, vector<pll>, cmp>q;
	for(int i = 1; i <= n;i++){
		cin >> a[i];
		prv[i] = i - 1, nxt[i] = i + 1;
		q.push({i, a[i]});
	}
	prv[n+1] = n, nxt[0] = 1, a[0] = a[n+1] = -inf;
	ll cur = (n + 1) / 2, cnt = 0, res = 0;
	while(cnt < cur){
		if(!q.size()) break;
		ll i = q.top().F, val = q.top().S; q.pop();
		if(!del[i] && i > 0 && i <= n){
			del[prv[i]] = del[nxt[i]] = 1;
			res += val;
			a[i] = a[prv[i]] + a[nxt[i]] - val;
			q.push({i, a[i]});
			nxt[i] = nxt[nxt[i]]; prv[i] = prv[prv[i]];
			nxt[prv[i]] = i;
			prv[nxt[i]] = i;
			cnt++;
		}
		ans[cnt] = max(ans[cnt], res);
	}
	for(int i = 1; i <= cur;i++) cout << ans[i] << ' ';
	cout << '\n';
}     
 
signed main()   
{  
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll tc = 1;
	//cin >> tc;
	while(tc--) to_thic_cau();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 616 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 616 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 476 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 640 KB Output is correct
21 Correct 71 ms 14072 KB Output is correct
22 Correct 73 ms 13956 KB Output is correct
23 Correct 106 ms 14016 KB Output is correct
24 Correct 67 ms 14016 KB Output is correct
25 Correct 52 ms 13796 KB Output is correct
26 Correct 80 ms 14012 KB Output is correct
27 Correct 67 ms 14012 KB Output is correct
28 Correct 88 ms 14092 KB Output is correct
29 Correct 68 ms 14048 KB Output is correct
30 Correct 79 ms 14180 KB Output is correct
31 Correct 84 ms 14016 KB Output is correct
32 Correct 55 ms 14016 KB Output is correct
33 Correct 71 ms 13760 KB Output is correct
34 Correct 61 ms 13980 KB Output is correct
35 Correct 62 ms 13860 KB Output is correct
36 Correct 83 ms 14012 KB Output is correct
37 Correct 86 ms 14016 KB Output is correct
38 Correct 88 ms 14012 KB Output is correct
39 Correct 79 ms 14012 KB Output is correct
40 Correct 64 ms 14016 KB Output is correct
41 Correct 56 ms 14000 KB Output is correct
42 Correct 76 ms 14016 KB Output is correct
43 Correct 65 ms 13984 KB Output is correct
44 Correct 61 ms 14184 KB Output is correct
45 Correct 68 ms 14012 KB Output is correct
46 Correct 56 ms 13988 KB Output is correct
47 Correct 87 ms 14012 KB Output is correct
48 Correct 57 ms 13756 KB Output is correct
49 Correct 56 ms 14012 KB Output is correct
50 Correct 60 ms 13756 KB Output is correct