Earliest Possible Day of Full Bloom LeetCode solution in C++

1
class Solution {
2
public:
3
int earliestFullBloom(vector<int> &plantTime, vector<int> &growTime) {
4
int n = plantTime.size();
5
// growTime larger first
6
vector<pair<int, int>> times(n);
7
for (int i = 0; i < n; i++) {
8
times[i].first = -growTime[i];
9
times[i].second = plantTime[i];
10
}
11
sort(times.begin(), times.end());
12
int tot = 0;
13
int cur = 0;
14
for (int i = 0; i < n; i++) {
15
tot = max(tot, cur + times[i].second - times[i].first);
16
cur += times[i].second;
17
}
18
return tot;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0