이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |