Last active
November 12, 2023 14:35
-
-
Save razimantv/d449717312cd7e2c9237bc5bfc8e38cb to your computer and use it in GitHub Desktop.
Superman Diwali solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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