Skip to content

Commit

Permalink
update: May16, greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
aucker committed May 16, 2024
1 parent f14bc19 commit 9e0427e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions daily/May16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
#include <algorithm>
#include <numeric>

using std::accumulate;
using std::max_element;
using std::vector;

class Solution {
public:
/**
* @brief LC1953: max week numbers you can work
*
* @param milestones
* @return int64_t
*/
auto NumberOfWeeks(vector<int>& milestones) -> int64_t {
int64_t s = accumulate(milestones.begin(), milestones.end(), 0LL);
int64_t m = *max_element(milestones.begin(), milestones.end());
return m > s - m + 1 ? (s - m) * 2 + 1 : s;
}
};

0 comments on commit 9e0427e

Please sign in to comment.