add: 220325 [cpp]

This commit is contained in:
Lam Haoyin 2022-03-25 19:25:26 +08:00
parent 9f41f5480a
commit 4b2864ed60
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 21 additions and 1 deletions

20
cpp/2203/220325.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <vector>
#include <iostream>
#include <algorithm>
class Solution {
public:
static int twoCitySchedCost(std::vector<std::vector<int>>& costs) {
int n = costs.size() >> 1, ret = 0;
std::sort(costs.begin(), costs.end(), [](const std::vector<int>& x, const std::vector<int>& y) { return x[0] - x[1] < y[0] - y[1]; });
for (int i = 0; i < n; ++i)
ret += costs[i][0] + costs[i + n][1];
return ret;
}
};
int main() {
std::vector<std::vector<int>> args {{10,20},{30,200},{400,50},{30,20}};
std::cout << Solution::twoCitySchedCost(args);
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(2203)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2203 220324-CN.cpp)
ADD_EXECUTABLE(2203 220325.cpp)