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

Commit dff4abf

Browse files
Update 2412.Minimum-Money-Required-Before-Transactions.cpp
1 parent 28c3a0a commit dff4abf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

‎Greedy/2412.Minimum-Money-Required-Before-Transactions/2412.Minimum-Money-Required-Before-Transactions.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class Solution {
33
public:
44
long long minimumMoney(vector<vector<int>>& transactions)
55
{
6-
76
sort(transactions.begin(), transactions.end(), [](vector<int>&a, vector<int>&b){return a[1]<b[1];});
87
LL maxCostForNetGain = 0;
98

@@ -25,8 +24,9 @@ class Solution {
2524
}
2625
}
2726

28-
cur += abs(histLow);
27+
cur -= maxCostForNetGain;
28+
histLow = min(histLow, cur);
2929

30-
return abs(histLow) + max(0LL, maxCostForNetGain - cur);
30+
return abs(histLow);
3131
}
3232
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /