# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
58173 |
2018-07-17T05:34:15 Z |
노영훈(#1688) |
Candies (JOI18_candies) |
C++11 |
|
5000 ms |
8056 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=500010, inf=2e9;
list<ll> X;
int n, A[MX];
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>A[i];
for(int i=1; i<=n; i++) X.push_back(A[i]);
ll ans=0;
for(int j=1; j<=(n+1)/2; j++){
auto it=max_element(X.begin(), X.end());
ans+=*it;
// for(int x:X) cout<<x<<' ';
// cout<<'\n';
cout<<ans<<'\n';
if(it==X.begin()){
X.erase(it, next(next(it)));
continue;
}
if(next(it)==X.end()){
X.erase(prev(it), next(it));
continue;
}
*it = *prev(it) + *next(it) - *it;
X.erase(prev(it));
X.erase(next(it));
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
616 KB |
Output is correct |
3 |
Correct |
7 ms |
688 KB |
Output is correct |
4 |
Correct |
7 ms |
688 KB |
Output is correct |
5 |
Correct |
7 ms |
688 KB |
Output is correct |
6 |
Correct |
7 ms |
688 KB |
Output is correct |
7 |
Correct |
7 ms |
688 KB |
Output is correct |
8 |
Correct |
6 ms |
688 KB |
Output is correct |
9 |
Correct |
6 ms |
688 KB |
Output is correct |
10 |
Correct |
6 ms |
688 KB |
Output is correct |
11 |
Correct |
7 ms |
688 KB |
Output is correct |
12 |
Correct |
7 ms |
744 KB |
Output is correct |
13 |
Correct |
6 ms |
776 KB |
Output is correct |
14 |
Correct |
7 ms |
776 KB |
Output is correct |
15 |
Correct |
8 ms |
776 KB |
Output is correct |
16 |
Correct |
7 ms |
812 KB |
Output is correct |
17 |
Correct |
6 ms |
812 KB |
Output is correct |
18 |
Correct |
6 ms |
812 KB |
Output is correct |
19 |
Correct |
5 ms |
812 KB |
Output is correct |
20 |
Correct |
6 ms |
812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
7 ms |
616 KB |
Output is correct |
3 |
Correct |
7 ms |
688 KB |
Output is correct |
4 |
Correct |
7 ms |
688 KB |
Output is correct |
5 |
Correct |
7 ms |
688 KB |
Output is correct |
6 |
Correct |
7 ms |
688 KB |
Output is correct |
7 |
Correct |
7 ms |
688 KB |
Output is correct |
8 |
Correct |
6 ms |
688 KB |
Output is correct |
9 |
Correct |
6 ms |
688 KB |
Output is correct |
10 |
Correct |
6 ms |
688 KB |
Output is correct |
11 |
Correct |
7 ms |
688 KB |
Output is correct |
12 |
Correct |
7 ms |
744 KB |
Output is correct |
13 |
Correct |
6 ms |
776 KB |
Output is correct |
14 |
Correct |
7 ms |
776 KB |
Output is correct |
15 |
Correct |
8 ms |
776 KB |
Output is correct |
16 |
Correct |
7 ms |
812 KB |
Output is correct |
17 |
Correct |
6 ms |
812 KB |
Output is correct |
18 |
Correct |
6 ms |
812 KB |
Output is correct |
19 |
Correct |
5 ms |
812 KB |
Output is correct |
20 |
Correct |
6 ms |
812 KB |
Output is correct |
21 |
Execution timed out |
5068 ms |
8056 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |