답안 #920974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920974 2024-02-03T08:35:02 Z vjudge1 Potatoes and fertilizers (LMIO19_bulves) C++17
24 / 100
105 ms 7268 KB
#include <iostream>
#include <queue>

using namespace std;
#define N 500005

int n, a[N], b[N];
priority_queue<pair<int, int>> pq, qq;
long long cost;

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;
        pq.emplace(i, a);
        while (b and pq.size())
        {
            auto [j, aa] = pq.top(); pq.pop();
            auto u = min(b, aa);
            cost += 1ll*u*(i-j);
            b -= u;
            if (aa > u) pq.emplace(j, aa - u);
        }
        if (b)
        {
            qq.emplace(i, b);
        }
        while (pq.size() and qq.size())
        {
            auto [j, aa] = pq.top(); pq.pop();
            auto [k, bb] = qq.top(); qq.pop();
            auto u = min(aa, bb);
            cost += 1ll*abs(j-k)*u;
            if (aa > u) pq.emplace(j, aa - u);
            if (bb > u) qq.emplace(k, bb - u);
        }
    }
    cout<<cost;
    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 9 ms 604 KB Output is correct
5 Correct 17 ms 968 KB Output is correct
6 Correct 48 ms 3668 KB Output is correct
7 Correct 105 ms 6976 KB Output is correct
8 Correct 97 ms 7268 KB Output is correct
9 Correct 89 ms 4432 KB Output is correct
10 Correct 47 ms 2388 KB Output is correct
11 Correct 47 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 9 ms 604 KB Output is correct
5 Correct 17 ms 968 KB Output is correct
6 Correct 48 ms 3668 KB Output is correct
7 Correct 105 ms 6976 KB Output is correct
8 Correct 97 ms 7268 KB Output is correct
9 Correct 89 ms 4432 KB Output is correct
10 Correct 47 ms 2388 KB Output is correct
11 Correct 47 ms 2388 KB Output is correct
12 Incorrect 30 ms 2104 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -