# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
698071 | finn__ | City (BOI06_city) | C++17 | 1084 ms | 16748 KiB |
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 <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
uint64_t n, t, k;
cin >> n >> t >> k;
uint64_t const w = sqrt(n);
vector<uint64_t> c(k), curr_floor(w, 0);
for (uint64_t &x : c)
cin >> x;
auto compare_cost = [&c, &curr_floor, &t](uint64_t x, uint64_t y)
{
return t * x + c[curr_floor[x]] > t * y + c[curr_floor[y]];
};
priority_queue<uint64_t, vector<uint64_t>, decltype(compare_cost)> q(compare_cost);
for (uint64_t i = 0; i < w; i++)
q.push(i);
uint64_t leftover = n, cost = 0;
while (leftover)
{
uint64_t x = q.top();
q.pop();
cost += min(leftover, 4 * (x + 1)) * (t * x + c[curr_floor[x]]);
leftover -= min(leftover, 4 * (x + 1));
curr_floor[x]++;
if (curr_floor[x] < k)
q.push(x);
}
cout << cost << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |