| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1263371 | SmuggingSpun | Candies (JOI18_candies) | C++20 | 2 ms | 584 KiB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
int n;
cin >> n;
set<pair<ll, int>>s1;
set<pair<int, ll>>s2;
for(int i = 1; i <= n; i++){
ll x;
cin >> x;
s1.emplace(-x, i);
s2.emplace(i, -x);
}
s1.emplace(INF, 0);
s1.emplace(INF, n + 1);
s2.emplace(0, INF);
s2.emplace(n + 1, INF);
ll ans = 0;
for(int _ = 0; _ < (n >> 1); _++){
auto [x, i] = *s1.begin();
cout << (ans -= x) << "\n";
auto it = s2.lower_bound(make_pair(i, x));
auto a = *--it;
s1.erase(make_pair(a.second, a.first));
s2.erase(it++);
auto b = *it;
s1.erase(make_pair(b.second, b.first));
s2.erase(it++);
auto c = *it;
s1.erase(make_pair(c.second, c.first));
s2.erase(it);
s1.emplace(a.second + c.second - b.second, b.first);
s2.emplace(b.first, a.second + c.second - b.second);
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
