이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Point = pair<int, int>;
using idata = vector<int>;
struct Treap {
    vector<Point> points;
    void insert( Point point ) {
        points.push_back(point);
    }
    int query (int x) {
        int res = 0;
        for (Point &point : points) if (x >= point.first) res += point.second;
        return res;
    }
    void chmin (int until) {
        sort(points.begin(), points.end());
        int res = 0;
        int idx = 0;
        int lp  = -1;
        for (Point &point : points) {
            if (res + point.second > until) {
                idx ++;
                point.second = until - res;
                break ;
            }
            res += point.second;
            idx ++;
        }
        if (idx == points.size()) return ;
        points.resize(idx);
        if (res == until) return ;
    }
    Treap cut (int position) {
        Treap other;
        vector<Point> local;
        for (Point & point : points) {
            if (point.first <= position) local.push_back(point);
            else other.insert(point);
        }
        points = local;
        return other;
    }
    void show () {
        sort(points.begin(), points.end());
        for (Point &point : points)
            cout << point.first << ": " << point.second << endl;
    }
    int size () { return points.size(); }
    void swap (Treap &other) { points.swap(other.points); }
};
void compile (Treap &treap, int H_i, int C_i) {
    int chmin_left = treap.query( H_i );
    Treap right = treap.cut(H_i);
    right.insert({ H_i + 1, C_i });
    treap.insert({ - 1e9, C_i });
    treap.chmin( chmin_left );
    for (Point &point : right.points) treap.insert(point);
}
void merge (Treap &target, Treap &other) {
    if (target.size() < other.size())
        target.swap(other);
    
    for (Point point : other.points)
        target.insert(point);
}
vector<Treap> treapArray;
idata A, H, C;
signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    treapArray.resize(N);
    A.resize(N); H.resize(N); C.resize(N);
    for (int i = 0; i < N; i ++) {
        cin >> A[i] >> H[i] >> C[i];
        A[i] --;
        if ((i != 0 && A[i] > i - 1) || (i == 0 && A[i] != 0)) return 0;
    }
    
    for (int i = N - 1; i >= 0; i --) {
        compile(treapArray[i], H[i], C[i]);
        if (i == 0) continue ;
        merge(treapArray[A[i]], treapArray[i]);
    }
    cout << treapArray[0].query(1) << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
worst_reporter2.cpp: In member function 'void Treap::chmin(long long int)':
worst_reporter2.cpp:38:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if (idx == points.size()) return ;
      |             ~~~~^~~~~~~~~~~~~~~~
worst_reporter2.cpp:26:13: warning: unused variable 'lp' [-Wunused-variable]
   26 |         int lp  = -1;
      |             ^~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |