Submission #198787

# Submission time Handle Problem Language Result Execution time Memory
198787 2020-01-27T15:42:48 Z red1108 Candies (JOI18_candies) C++17
100 / 100
468 ms 17688 KB
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF = 2e16;
const int inf = 2e9;
ll in[200010],ans;
int n,l[200010],r[200010];
set<pll> SET;
int main(){
	fastio;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>in[i];
		SET.insert(pll(-in[i],i));
		l[i]=i-1;r[i]=i+1;
	}
	for(int j=1;j<=(n+1)/2;j++){
		pll t = pll(SET.begin()->fi, SET.begin()->se);
		SET.erase(t);
		ans -= t.fi;
		int i = t.se;
		if(l[i]!=0&&r[i]!=n+1) in[i] = max(in[r[i]] + in[l[i]] - in[i],-INF);
		else in[i] = -INF;
		SET.insert(pll(-in[i], i));
		SET.erase(pll(-in[l[i]],l[i]));
		SET.erase(pll(-in[r[i]],r[i]));
		l[i] = l[l[i]];
		r[i] = r[r[i]];
		r[l[i]] = i;
		l[r[i]] = i;
		cout<<ans<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 8 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 13 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 7 ms 508 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 7 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 8 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 13 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 7 ms 508 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 7 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 464 ms 17656 KB Output is correct
22 Correct 468 ms 17504 KB Output is correct
23 Correct 459 ms 17528 KB Output is correct
24 Correct 168 ms 17456 KB Output is correct
25 Correct 168 ms 17528 KB Output is correct
26 Correct 181 ms 17528 KB Output is correct
27 Correct 175 ms 17528 KB Output is correct
28 Correct 177 ms 17528 KB Output is correct
29 Correct 177 ms 17528 KB Output is correct
30 Correct 191 ms 17528 KB Output is correct
31 Correct 191 ms 17528 KB Output is correct
32 Correct 187 ms 17528 KB Output is correct
33 Correct 309 ms 17604 KB Output is correct
34 Correct 301 ms 17528 KB Output is correct
35 Correct 303 ms 17688 KB Output is correct
36 Correct 447 ms 17528 KB Output is correct
37 Correct 460 ms 17632 KB Output is correct
38 Correct 447 ms 17532 KB Output is correct
39 Correct 174 ms 17600 KB Output is correct
40 Correct 178 ms 17528 KB Output is correct
41 Correct 175 ms 17528 KB Output is correct
42 Correct 190 ms 17508 KB Output is correct
43 Correct 183 ms 17528 KB Output is correct
44 Correct 181 ms 17528 KB Output is correct
45 Correct 195 ms 17528 KB Output is correct
46 Correct 200 ms 17528 KB Output is correct
47 Correct 196 ms 17528 KB Output is correct
48 Correct 302 ms 17528 KB Output is correct
49 Correct 285 ms 17528 KB Output is correct
50 Correct 290 ms 17528 KB Output is correct