# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
654961 |
2022-11-02T08:53:11 Z |
onlk97 |
Candies (JOI18_candies) |
C++14 |
|
2 ms |
468 KB |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin>>n;
long long a[n+2];
a[0]=a[n+1]=-1e18;
for (int i=1; i<=n; i++) cin>>a[i];
long long l[n+1],r[n+1];
for (int i=1; i<=n; i++){
l[i]=i-1;
r[i]=i+1;
}
l[0]=0; r[n+1]=n+1;
bool used[n+2];
for (int i=0; i<=n+1; i++) used[i]=0;
set <pair <long long,int>,greater <pair <long long,int> > > s;
for (int i=1; i<=n; i++) s.insert(make_pair(a[i],i));
long long ans=0;
for (int iters=1; iters<=(n+1)/2; iters++){
die:;
pair <long long,int> tp=*s.begin(); s.erase(s.begin());
if (used[tp.second]) goto die;
ans+=tp.first;
cout<<ans<<'\n';
int ll=l[tp.second],rr=r[tp.second];
a[tp.second]=a[ll]+a[rr]-a[tp.second];
l[tp.second]=l[ll];
r[tp.second]=r[rr];
used[ll]=used[rr]=1;
r[l[tp.second]]=l[r[tp.second]]=tp.second;
if (ll>=1&&rr<=n) s.insert(make_pair(a[tp.second],tp.second));
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |