This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
std::vector<int> distribute_candies (std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v)
{
ll n = c.size();
list < ll > lv;
lv.insert (lv.end (), (ll) -1e18);
for (auto &x : v) lv.insert (lv.end (), x);
if (lv.size () > 2)
for (auto it = prev (lv.end (), 2);; --it)
{
if (*it >= 0 && *next (it, 1) >= 0) *it += *next (it, 1), lv.erase (next (it, 1));
if (*it <= 0 && *next (it, 1) <= 0) *it += *next (it, 1), lv.erase (next (it, 1));
if (it == lv.begin ()) break;
}
if (lv.size () > 3)
for (auto it = prev (lv.end (), 3);; --it)
{
if (next (it, 2) == lv.end ())
{
if (it == lv.begin ()) break;
continue;
}
if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0
&& *it >= -*next (it, 1) && *next (it, 2) >= -*next (it, 1))
*it += *next (it, 1) + *next (it, 2),
lv.erase (next (it, 1)), lv.erase (next (it, 1));
if (*it >= 0 && *next (it, 1) <= 0 && *next (it, 2) >= 0
&& -*it >= *next (it, 1) && -*next (it, 2) >= *next (it, 1))
*it += *next (it, 1) + *next (it, 2),
lv.erase (next (it, 1)), lv.erase (next (it, 1));
if (it == lv.begin ()) break;
}
vector < ll > ss;
for (auto &x : lv) ss.push_back (x);
ss.push_back (0);
map < ll, pair < int, bool > > mp;
for (int i = ss.size () - 2; i >= 0; --i)
{
if (mp.count (abs (ss[i])) == 0)
mp[abs (ss[i])] = { i, ss[i] >= 0 };
ss[i] += ss[i + 1];
}
vector < int > ans (n);
for (int i = 0; i < n; ++i)
{
auto it = mp.lower_bound (c[i])->second;
if (it.second) ans[i] = c[i] + ss[it.first + 1];
else ans[i] = ss[it.first + 1];
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |