-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2136.cpp
More file actions
24 lines (23 loc) · 819 Bytes
/
2136.cpp
File metadata and controls
24 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
static bool cmp(const pair<int, int>& p1, const pair<int, int>& p2) {
if (p1.first == p2.first) return p1.second > p2.second;
return p1.first > p2.first;
}
int earliestFullBloom(vector<int>& plantTime, vector<int>& growTime) {
int n = plantTime.size();
vector<pair<int,int>> growWithPlant(n);
for (int i = 0; i < n; ++i) {
growWithPlant[i].first = growTime[i];
growWithPlant[i].second = plantTime[i];
}
sort(growWithPlant.begin(), growWithPlant.end(), cmp);
int res = 0;
int plantSum = 0;
for (int i = 0; i < n; ++i) {
plantSum += growWithPlant[i].second;
res = max(res, plantSum + growWithPlant[i].first);
}
return res;
}
};