Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add #1402 in C++#113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fishercoder1534 merged 3 commits intofishercoder1534:masterfroml2zou:master
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,6 +86,7 @@ _If you like this project, please leave me a star._ ★
|1409|[Queries on a Permutation With Key](https://leetcode.com/problems/queries-on-a-permutation-with-key/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1409.java) | |Medium|Array|
|1408|[String Matching in an Array](https://leetcode.com/problems/string-matching-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1408.java) | |Easy|String|
|1403|[Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1403.java) | |Easy|Greedy, Sort|
|1402|[Reducing Dishes](https://leetcode.com/problems/reducing-dishes/)|[Solution](../master/cpp/_1402.cpp) | |Hard|Dynamic Programming|
|1401|[Circle and Rectangle Overlapping](https://leetcode.com/problems/circle-and-rectangle-overlapping/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1401.java) | |Medium|Geometry|
|1400|[Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1400.java) | |Medium|Greedy|
|1399|[Count Largest Group](https://leetcode.com/problems/count-largest-group/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1399.java) | |Easy|Array|
Expand Down
19 changes: 19 additions & 0 deletionscpp/_1402.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int maxSatisfaction(vector<int>& sat) {
// we'll greedily only consider a suffix of the sorted array
sort(sat.begin(), sat.end());
int cmax = 0;
int sum = 0;
int csum = 0;
int i = sat.size(); // iterate from n - 1 to 0
while(i--) {
// calulate current satisfaction
csum += sat[i];
sum += csum;
// compare with cmax
cmax = max(cmax, sum);
}
return cmax;
}
};

[8]ページ先頭

©2009-2025 Movatter.jp