# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
198786 |
2020-01-27T15:41:48 Z |
red1108 |
Candies (JOI18_candies) |
C++17 |
|
492 ms |
17656 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)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
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;
}
r[0]=1;
l[n+1]=n;
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 |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
504 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
7 ms |
504 KB |
Output is correct |
6 |
Correct |
7 ms |
508 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
7 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 |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
504 KB |
Output is correct |
14 |
Correct |
6 ms |
504 KB |
Output is correct |
15 |
Correct |
7 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
504 KB |
Output is correct |
18 |
Correct |
7 ms |
508 KB |
Output is correct |
19 |
Correct |
7 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
7 ms |
504 KB |
Output is correct |
3 |
Correct |
7 ms |
504 KB |
Output is correct |
4 |
Correct |
6 ms |
504 KB |
Output is correct |
5 |
Correct |
7 ms |
504 KB |
Output is correct |
6 |
Correct |
7 ms |
508 KB |
Output is correct |
7 |
Correct |
6 ms |
504 KB |
Output is correct |
8 |
Correct |
7 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 |
7 ms |
504 KB |
Output is correct |
12 |
Correct |
7 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
504 KB |
Output is correct |
14 |
Correct |
6 ms |
504 KB |
Output is correct |
15 |
Correct |
7 ms |
504 KB |
Output is correct |
16 |
Correct |
6 ms |
504 KB |
Output is correct |
17 |
Correct |
6 ms |
504 KB |
Output is correct |
18 |
Correct |
7 ms |
508 KB |
Output is correct |
19 |
Correct |
7 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
461 ms |
17528 KB |
Output is correct |
22 |
Correct |
456 ms |
17528 KB |
Output is correct |
23 |
Correct |
482 ms |
17456 KB |
Output is correct |
24 |
Correct |
178 ms |
17528 KB |
Output is correct |
25 |
Correct |
176 ms |
17512 KB |
Output is correct |
26 |
Correct |
179 ms |
17528 KB |
Output is correct |
27 |
Correct |
188 ms |
17528 KB |
Output is correct |
28 |
Correct |
187 ms |
17512 KB |
Output is correct |
29 |
Correct |
192 ms |
17528 KB |
Output is correct |
30 |
Correct |
201 ms |
17528 KB |
Output is correct |
31 |
Correct |
187 ms |
17656 KB |
Output is correct |
32 |
Correct |
192 ms |
17656 KB |
Output is correct |
33 |
Correct |
308 ms |
17528 KB |
Output is correct |
34 |
Correct |
303 ms |
17528 KB |
Output is correct |
35 |
Correct |
301 ms |
17656 KB |
Output is correct |
36 |
Correct |
492 ms |
17608 KB |
Output is correct |
37 |
Correct |
448 ms |
17528 KB |
Output is correct |
38 |
Correct |
480 ms |
17576 KB |
Output is correct |
39 |
Correct |
179 ms |
17528 KB |
Output is correct |
40 |
Correct |
179 ms |
17564 KB |
Output is correct |
41 |
Correct |
174 ms |
17528 KB |
Output is correct |
42 |
Correct |
181 ms |
17528 KB |
Output is correct |
43 |
Correct |
178 ms |
17448 KB |
Output is correct |
44 |
Correct |
187 ms |
17656 KB |
Output is correct |
45 |
Correct |
224 ms |
17528 KB |
Output is correct |
46 |
Correct |
197 ms |
17528 KB |
Output is correct |
47 |
Correct |
189 ms |
17528 KB |
Output is correct |
48 |
Correct |
307 ms |
17656 KB |
Output is correct |
49 |
Correct |
309 ms |
17476 KB |
Output is correct |
50 |
Correct |
292 ms |
17656 KB |
Output is correct |