From 538bb490d3bb229d897bcb090cf7a0f554e6bf4f Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:43:31 +0800 Subject: [PATCH] new file: P14361.cpp --- P14361.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 P14361.cpp diff --git a/P14361.cpp b/P14361.cpp new file mode 100644 index 0000000..b28ad1b --- /dev/null +++ b/P14361.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int main() +{ + int T; + scanf("%d", &T); + while (T--) + { + vector diffs[3]; + int n, total = 0; + scanf("%d", &n); + for (int i = 0; i < n; i++) + { + int val[3]; + for (int j = 0; j < 3; j++) + scanf("%d", &val[j]); + int best = 0; + for (int j = 1; j < 3; j++) + if (val[j] > val[best]) + best = j; + total += val[best]; + int second = (best == 0) ? 1 : 0; + for (int j = 0; j < 3; j++) + if (j != best && val[j] > val[second]) + second = j; + diffs[best].push_back(val[best] - val[second]); + } + for (int i = 0; i < 3; i++) + { + if ((int)diffs[i].size() > n / 2) + { + sort(diffs[i].begin(), diffs[i].end()); + int drop = (int)diffs[i].size() - n / 2; + for (int j = 0; j < drop; j++) + total -= diffs[i][j]; + } + } + printf("%d\n", total); + } + return 0; +} \ No newline at end of file