mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
routine
This commit is contained in:
15
25/12/comp/28q2.cpp
Normal file
15
25/12/comp/28q2.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <algorithm>
|
||||
class Solution {
|
||||
public:
|
||||
long long minimumCost(int cost1, int cost2, int costBoth, int need1, int need2) {
|
||||
if (costBoth >= cost1 + cost2) {
|
||||
return (long long)cost1 * need1 + (long long)cost2 * need2;
|
||||
}
|
||||
int m1 = std::min(need1,need2);
|
||||
long long a2 = (long long)std::max(need1,need2) * costBoth;
|
||||
long long ans = (long long)m1 * costBoth;
|
||||
ans += (long long)(need1 - m1) * cost1;
|
||||
ans += (long long)(need2 - m1) * cost2;
|
||||
return std::min(ans,a2);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user