From 4b2864ed6066b5e94ddc09563208e899470287d2 Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Fri, 25 Mar 2022 19:25:26 +0800 Subject: [PATCH] add: 220325 [cpp] --- cpp/2203/220325.cpp | 20 ++++++++++++++++++++ cpp/2203/CMakeLists.txt | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 cpp/2203/220325.cpp diff --git a/cpp/2203/220325.cpp b/cpp/2203/220325.cpp new file mode 100644 index 0000000..76eceaa --- /dev/null +++ b/cpp/2203/220325.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +class Solution { +public: + static int twoCitySchedCost(std::vector>& costs) { + int n = costs.size() >> 1, ret = 0; + std::sort(costs.begin(), costs.end(), [](const std::vector& x, const std::vector& 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> args {{10,20},{30,200},{400,50},{30,20}}; + std::cout << Solution::twoCitySchedCost(args); + return 0; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 474ca25..2956dec 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220324-CN.cpp) +ADD_EXECUTABLE(2203 220325.cpp)