commit b99bcb5b034885f39b9e362dbdd54c180c444d17
parent bc8800af2930d30f827ddc1b7d881ada5d80cd6a
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 16 Nov 2023 11:58:03 +0000
1 Random Problem
Diffstat:
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/Problems/2491.cpp b/Problems/2491.cpp
@@ -0,0 +1,26 @@
+class Solution {
+ public:
+ long long dividePlayers(const vector<int> &skill) const {
+ static int count[1001];
+ memset(count, 0x00, sizeof(count));
+
+ const int sum = accumulate(begin(skill), end(skill), 0);
+ const int n = size(skill), goal = sum / (n / 2);
+
+ if (goal * n / 2 != sum) return -1;
+
+ long long res = 0, cnt = 0;
+ for (const int n : skill) {
+ const int target = goal - n;
+ if (!count[target])
+ count[n]++;
+ else {
+ count[target]--;
+ res += target * n;
+ cnt += 2;
+ }
+ }
+
+ return cnt == n ? res : -1;
+ }
+};
diff --git a/README.md b/README.md
@@ -863,6 +863,7 @@ for solving problems.
| 2483 | Medium | [Minimum Penalty for a Shop](Problems/2483.cpp) |
| 2486 | Medium | [Append Characters to String to Make Subsequence](Problems/2486.cpp) |
| 2487 | Medium | [Remove Nodes From Linked List](Problems/2487.cpp) |
+| 2491 | Medium | [Divide Players Into Teams of Equal Skill](Problems/2491.cpp) |
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
| 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) |
| 2498 | Medium | [Frog Jump II](Problems/2498.cpp) |