| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1268935 | hubertm | Potatoes and fertilizers (LMIO19_bulves) | C++20 | 70 ms | 8380 KiB |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> pref(n + 1);
for (int i = 1; i <= n; ++i)
{
int a, b;
cin >> a >> b;
pref[i] = pref[i - 1] + a - b;
}
long long value = 0;
priority_queue<long long> points;
for (int i = 1; i <= n; ++i)
{
int v = pref[i];
if (v < 0)
{
value += -v;
v = 0;
}
else if (v > pref[n])
{
value += v - pref[n];
v = pref[n];
}
if (points.empty())
{
points.push(v);
continue;
}
points.push(v);
points.push(v);
int p = points.top();
points.pop();
value += p - points.top();
value += points.top() - v;
}
cout << value << '\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... | ||||
