Skip to content

Instantly share code, notes, and snippets.

@razimantv
Last active November 12, 2023 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save razimantv/d449717312cd7e2c9237bc5bfc8e38cb to your computer and use it in GitHub Desktop.
Save razimantv/d449717312cd7e2c9237bc5bfc8e38cb to your computer and use it in GitHub Desktop.
Superman Diwali solution
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N, H, I;
cin >> N >> H >> I;
vector<pair<int, int>> people;
for (int i=0; i<N; ++i) {
int u, h;
cin >> u;
while (u--) {
cin >> h;
people. push_back({h,i});
}
}
sort(people.begin(), people.end());
vector<int> best(H+1), bestb(N);
int cur = H;
for(int i=people.size()-1; i>=0; --i) {
auto [h, b] = people [i];
while (cur > h) {
best [cur-1] = best [cur];
--cur;
}
bestb[b] += 1;
if(h+I <= H) bestb[b] = max(bestb[b], best[h+I]+1);
best[h] = max(best[h], bestb[b]);
//cerr << b << " " << h << " " << best[h] << " " << bestb[b] << "\n";
}
cout << best[cur] << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment