class Solution {
using pii = pair<int, int>;
public:
int earliestFullBloom(vector<int>& plantTime, vector<int>& growTime) {
int n = plantTime.size();
vector<pii> time;
for(int i = 0; i < n; ++i) {
time.push_back({plantTime[i], growTime[i]});
}
sort(time.begin(), time.end(), [](pii& p1, pii& p2) {
if(p1.second == p2.second) return p1.first > p2.first;
return p1.second > p2.second;
});
int ret = 0;
int start = 0;
for(auto [plant, grow]: time) {
ret = max(start + plant + grow, ret);
start += plant;
}
return ret;
}
};
// 1 4 3
// 2 3 1
// longest growing time first
// X X X X O O O 1 2
// X O O
// X X X O
// 1 2 3 2
// 2 1 2 1
// 1 2 3 4 5 6 7 8 9
// X O O
// X X X O O
// X X O
// X X O
// X X X O O
// X X O
// X X O
// X X X O O
// X X X O O
// X X O O O
// X X O O O
// X X X O O