Submission #227207

#TimeUsernameProblemLanguageResultExecution timeMemory
227207nvmdavaCandies (JOI18_candies)C++17
100 / 100
603 ms29008 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define N 200005 const ll MOD = 1'000'000'007; const int INF = 0x3f3f3f3f; set<pair<ll, ll> > a, p; ll ans = 0; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int x, i = 1; i <= n; ++i){ cin>>x; x *= -1; a.insert({i, x}); p.insert({x, i}); } a.insert({0, 1'000'000'000'000'000'000}); a.insert({n + 1, 1'000'000'000'000'000'000}); p.insert({1'000'000'000'000'000'000, 0}); p.insert({1'000'000'000'000'000'000, n + 1}); for(int i = 1; i <= (n + 1) / 2; ++i){ pair<ll, ll> x = *p.begin(); swap(x.ff, x.ss); ans -= x.ss; auto it = a.find(x); x.ss = 0; --it; x.ss += it -> ss; p.erase({it -> ss, it -> ff}); it = a.erase(it); x.ss -= it -> ss; p.erase({it -> ss, it -> ff}); it = a.erase(it); x.ss += it -> ss; p.erase({it -> ss, it -> ff}); it = a.erase(it); a.insert(x); p.insert({x.ss, x.ff}); cout<<ans<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...