I was trying to implement this bronze question (The bucket list), and only pass the first test case and wanted to know if I am completely off or maybe if I can fix something it would work but I just do not know it yet.
My idea is as follows: sort the inputs by start time, for each input line update the available buckets based on the current start time from the previous end time. We bound this by 0 or a positive number and, if 0, the current bucket is free. We then find each bucket that is free and subtract the label of the bucket until we bet b < 0. Since it wants the maximum number of buckets used, we can use a unordered_set to track buckets used and just return its size.
I initially tried sorting the inputs by end time but I think that would lead to subtracting buckets in the wrong order.
int main() {
int n;
cin >> n;
vector<tuple<int, int, int>> v(n);
vector<pair<int, bool>> buckets(11, {0, false});
for (auto&& i : v) {
int s, t, b;
cin >> s >> t >> b;
i = {s, t, b};
}
sort(begin(v), end(v));
unordered_set<int> ret;
for (auto& [s, t, b] : v) {
for (int i{1}; i < buckets.size(); ++i) {
buckets[i].first = max(0, buckets[i].first - s);
if (!buckets[i].first) buckets[i].second = false;
}
int pos{1};
while (b > 0 && pos < buckets.size()) {
if (!buckets[pos].second) {
buckets[pos] = {t, true};
b -= pos;
ret.insert(pos);
}
++pos;
}
}
// for (const auto& i : ret) cout << i << " ";
// cout << '\n';
cout << ret.size();