p148.ans1
======================
1
2

=================
p148.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<tuple<int, int, int>> a;

void read() {
    cin >> n;
    a.resize(n);
    for(auto& [x, y, z]: a) {
        cin >> x >> y >> z;
    }
}

void solve() {
    // We pick a single top level to start the chain reaction by paying to
    // depressurize it: its water W pours onto the next level, and from there
    // on the falling water w_fall accumulates downward. At each level, if the
    // accumulated water already exceeds the level's capacity L it breaks for
    // free and we keep falling; otherwise we must pay P to break it (and add
    // its own W to the cascade). The total cost of a given start is the sum of
    // the P of the levels we had to pay for; once w_fall exceeds the maximum
    // possible capacity (15000) the rest collapses for free, so we stop early.
    // We try every start, keep the cheapest, and replay it to list which
    // levels we ended up paying to depressurize.

    int ans = get<2>(a[n - 1]);
    int best_pos = n - 1;

    for(int start = 0; start < n; start++) {
        int w_fall = 0, candidate = 0;
        for(int i = start; i < n; i++) {
            auto [x, y, z] = a[i];
            w_fall += x;
            if(w_fall <= y) {
                candidate += z;
            } else if(w_fall > 15000) {
                break;
            }
        }

        if(candidate < ans) {
            ans = candidate;
            best_pos = start;
        }
    }

    int w_fall = 0;
    vector<int> best;
    for(int i = best_pos; i < n; i++) {
        auto [x, y, z] = a[i];
        w_fall += x;
        if(w_fall <= y) {
            best.push_back(i + 1);
        }
    }

    for(auto x: best) {
        cout << x << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p148.in1
======================
3
1000 1000 1
0 1000 2
2 10 100

=================
statement.txt
======================
148. B-Station
time limit per test: 0.25 sec.
memory limit per test: 4096 KB
input: standard input
output: standard output



There is a half-waterlogged underwater station not far from the famous country Berland. The station consists of N levels. The following information is known about each level: Wi - the weigth of water on i-th before the act of terrorism, Li - the weight of water the i-th level can hold, and Pi - amount of money terrorist are required to depressurize i-th level. All the water from the depressurized level pours to the next level. If the weight of the water on i-th level is more then Li, then it becomes depressurized. The terrorists from Pivland want to depressurize the last (N-th) level spending the least amount of money. They hired you to do this.

Input
The first line of input contains the natural number N (1<=N<=15000). Each of the following N lines contains 3 numbers Wi, Li, Pi (0<=Wi,Li,Pi<=15000).

Output
Write to the output the numbers of levels, which must be depressurized.

Sample test(s)

Input
3
1000 1000 1
0 1000 2
2 10 100

Output
1
2
Author:	Andrew V. Lazarev
Resource:	Saratov Regional Olympiad, 2002
Date:	Spring, 2002





=================
