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;
typedef long long ll;
ll n, a, b, finAns;
vector<pair<ll, ll> > masts;
set<pair<pair<ll, ll>, ll> > numAtHeight;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
masts.push_back({a, b});
}
sort(masts.begin(), masts.end());
finAns = 0;
ll prevHeight = 0;
ll index = -1;
for (auto i : masts)
{
index++;
ll numFlags = i.second;
if(i.first > prevHeight) {
while (prevHeight < i.first and numFlags > 0)
{
numAtHeight.insert({{1, prevHeight}, index});
numFlags--;
prevHeight++;
}
}
auto it = numAtHeight.begin();
while (numFlags > 0)
{
auto n = next(it, 1);
if (it->second != index)
{
finAns += it->first.first;
numAtHeight.insert({{it->first.first+1, it->first.second}, index});
numAtHeight.erase(it);
numFlags--;
}
it = n;
}
}
cout << finAns << "\n";
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |