# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
58153 | 2018-07-17T04:32:40 Z | 김세빈(#1689) | Candies (JOI18_candies) | C++11 | 7 ms | 504 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <ll, ll> pll; set <pll> S, P; ll n, ans; int main() { ll i, a, k; pll p, s, s_p, s_n; scanf("%lld", &n); for(i=0;i<n;i++){ scanf("%lld", &a); S.insert(pll(i, a)); P.insert(pll(-a, i)); } for(i=0;i+i<n;i++){ p = *P.begin(); ans -= p.first; s = pll(p.second, -p.first); k = -s.second; auto it = S.lower_bound(s); if(it != S.begin()){ auto it_p = it; it_p --; s_p = *it_p; k += s_p.second; S.erase(s_p); P.erase(pll(-s_p.second, s_p.first)); } it = S.lower_bound(s); { auto it_n = it; it_n ++; if(it_n != S.end()){ s_n = *it_n; k += s_n.second; S.erase(s_n); P.erase(pll(-s_n.second, s_n.first)); } } printf("%lld\n", ans); P.erase(p); S.erase(s); S.insert(pll(s.first, k)); P.insert(pll(-k, s.first)); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |