leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2136.cpp (508B)


      1 class Solution {
      2   public:
      3     int earliestFullBloom(const vector<int> &plantTime, const vector<int> &growTime) const {
      4         const int n = size(plantTime);
      5         static int idxs[100001];
      6 
      7         iota(idxs, idxs + n, 0);
      8         sort(idxs, idxs + n, [&](int a, int b) { return growTime[a] > growTime[b]; });
      9 
     10         int res = 0, acc = 0;
     11         for (const int i : span(idxs, n)) {
     12             acc += plantTime[i];
     13             res = max(res, acc + growTime[i]);
     14         }
     15 
     16         return res;
     17     }
     18 };