답안 #578407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578407 2022-06-16T16:55:48 Z Alexandruabcde Potatoes and fertilizers (LMIO19_bulves) C++14
0 / 100
101 ms 44116 KB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 5e5 + 5;
typedef long long LL;

struct SlopeTrick {
    LL a, b;

    priority_queue <LL> *H;

    SlopeTrick () {
        a = b = 0;

        H = new priority_queue<LL>;
    }

    SlopeTrick operator += (SlopeTrick other) {
        a += other.a;
        b += other.b;

        if (H->size() > other.H->size())
            swap(H, other.H);

        while (!other.H->empty()) {
            H->push(other.H->top());
            other.H->pop();
        }

        while (a > 0) {
            -- a;
            b += H->top();
            H->pop();
        }

        return *this;
    }

    SlopeTrick Evaluate () {
        while (a > 0) {
            -- a;
            b += H->top();
            H->pop();
        }

        return *this;
    }
};

int N;
LL D[NMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for (int i = 1; i <= N; ++ i ) {
        LL A, B;
        cin >> A >> B;

        D[i] = D[i-1] + A - B;
    }
}

void Solve () {
    SlopeTrick ans;
    for (int i = 1; i < N; ++ i ) {
        SlopeTrick aux;
        aux.a = 1;
        aux.b = -D[i];

        if (D[i] > D[N]) ans.b += (D[i] - D[N]);
        if (D[i] < 0) D[i] = 0;

        aux.H->push(D[i]);
        aux.H->push(D[i]);

        ans += aux;
    }

    ans.Evaluate();

    cout << ans.b << '\n';
}

int main () {
    Read();
    Solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 101 ms 43960 KB Output is correct
3 Incorrect 94 ms 44116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 101 ms 43960 KB Output is correct
3 Incorrect 94 ms 44116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 101 ms 43960 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 30 ms 5652 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 101 ms 43960 KB Output is correct
3 Incorrect 94 ms 44116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 101 ms 43960 KB Output is correct
3 Incorrect 94 ms 44116 KB Output isn't correct
4 Halted 0 ms 0 KB -