— size of array
— array of numbers
This is a minimax game: Alice wants to minimize the final score, Bob wants to maximize it. Both play optimally, and Alice moves first.
Recall that the arithmetic mean uses floor division: .
With only elements, Alice removes one and Bob removes another, leaving a single element as the final score. There are only choices for Alice and remaining choices for Bob — we can check all possibilities with conditional statements.
Time complexity:
Space complexity:
If all values are equal to some constant , then the arithmetic mean is before removal and after removal. The score never changes, so the answer is always .
Time complexity:
Space complexity:
We brute-force the minimax. For each possible choice that Alice can remove, we simulate Bob's optimal response: Bob will pick the element () that maximizes the final score . This means Bob will remove the smallest remaining element (since removing a smaller value keeps the sum larger).
For each Alice choice , we compute the best Bob can achieve. Alice will choose the that minimizes this value. We then compare the result to the initial score.
Time complexity:
Space complexity:
Alice wants to reduce the final score as much as possible, so her optimal strategy is to remove the largest element — this reduces the sum maximally. Bob wants to keep the final score as high as possible, so his optimal strategy is to remove the smallest remaining element — this preserves the sum as much as possible.
Algorithm:
Time complexity:
Space complexity:
Tie#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
long long sumAll = 0;
for (int i = 0; i < n; i++)
sumAll += a[i];
long long initial = sumAll / n;
long long final_score = (sumAll - a[0] - a[n - 1]) / (n - 2);
if (final_score < initial)
cout << "Alice" << endl;
else if (final_score == initial)
cout << "Tie" << endl;
else
cout << "Bob" << endl;
return 0;
}