답안 #870421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870421 2023-11-07T21:44:46 Z DylanSmith Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
158 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)

mt19937 rng;

void solve() {
    int N; cin >> N;
    priority_queue<ll> left, right;
    for (int i = 0; i < 1000000; i++) left.push(0), right.push(0);
    ll h = 0;
    ll lOff = 0, rOff = 0;
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        rOff += a;
        lOff -= b;
        rOff -= b;
        if (i + 1 < N) {
            h += abs(-right.top() + rOff);
            if (0 < -right.top() + rOff) {
                left.push(-lOff);
                h -= (-right.top() + rOff) - (left.top() + lOff);
                right.push(-(left.top() + lOff - rOff));
                left.pop();
            } else {
                right.push(rOff);
            }
            if (0 < -right.top() + rOff) {
                left.push(-lOff);
            } else {
                right.push(rOff);
                left.push(-right.top() + rOff - lOff);
                right.pop();
            }
        }
    }
    ll a = 0;
    while (left.top() + lOff >= 0) {
        h += a * ((-right.top() + rOff) - (left.top() + lOff));
        a--;
        right.push(-(left.top() + lOff - rOff));
        left.pop();
    }
    while (-right.top() + rOff < 0) {
        left.push(-right.top() + rOff - lOff);
        right.pop();
        a++;
        h += a * ((-right.top() + rOff) - (left.top() + lOff));
    }
    h -= a * (-right.top() + rOff);
    cout << h << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16304 KB Output is correct
2 Runtime error 158 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16304 KB Output is correct
2 Runtime error 158 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16304 KB Output is correct
2 Runtime error 158 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16304 KB Output is correct
2 Runtime error 158 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16304 KB Output is correct
2 Runtime error 158 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -