2136. 全部开花的最早一天 - 力扣(LeetCode)
简单的贪心然后结构体排序(也可以创建数组记录位置访问)
class Solution {
public:
struct node
{
int id, p, g;
node(int a,int b, int c) : id(a), p(b), g(c){};
};
int earliestFullBloom(vector<int>& plantTime, vector<int>& growTime)
{
vector<node>v;
int n = plantTime.size();
for(int i = 0; i < n; i++)
v.emplace_back(i,plantTime[i],growTime[i]);
sort(v.begin(),v.end(),[&](auto x,auto y) {return x.g > y.g;});
int ans = 0, pre = 0;
for(auto x : v)
{
ans = max(ans, pre + x.p + x.g);
pre += x.p;
}
return ans;
}
};