# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1195776 | badge881 | Bikeparking (EGOI24_bikeparking) | C++20 | 99 ms | 15444 KiB |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n;
vector<int> x, y;
int main()
{
scanf("%d", &n);
x.resize(n), y.resize(n);
for (int i = 0; i < n; i++)
scanf("%d", &x[i]);
for (int i = 0; i < n; i++)
scanf("%d", &y[i]);
int sm = 0;
for (int i = 0; i < n; i++)
sm += y[i];
for (int i = 0; i < n; i++)
{
x[i] = min(sm, x[i]);
sm -= x[i];
}
int ans = 0;
set<int> st;
for (int i = n - 1; i >= 0; i--)
{
while (x[i] > 0 && st.size())
{
int j = *st.begin();
int mi = min(y[j], x[i]);
x[i] -= mi;
y[j] -= mi;
ans += mi;
if (y[j] == 0)
st.erase(j);
}
if (y[i] > 0)
st.insert(i);
}
for (int i = n - 1; i >= 0; i--)
while (x[i] > 0)
{
int j = *st.begin();
int mi = min(x[i], y[j]);
x[i] -= mi;
y[j] -= mi;
if (i > j)
ans -= mi;
if (y[j] == 0)
st.erase(j);
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |