#include <iostream> #include <vector> #include <cmath> using namespace std; // Funkcja do obliczania kombinacji C(n, 3) = n! / (3! * (n-3)!) long long comb(int n) { if (n < 3) return 0; return (long long)n * (n - 1) * (n - 2) / 6; } // Funkcja do obliczania minimalnej liczby graczy int minimal_players_for_games(const vector<int>& games) { int players = 3; while (true) { long long total_games = 0; for (int game_count : games) { total_games += comb(players); } if (total_games >= games.size()) { return players; } players++; } } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> games(n); for (int i = 0; i < n; ++i) { cin >> games[i]; } cout << minimal_players_for_games(games) << endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <iostream> #include <vector> #include <cmath> using namespace std; // Funkcja do obliczania kombinacji C(n, 3) = n! / (3! * (n-3)!) long long comb(int n) { if (n < 3) return 0; return (long long)n * (n - 1) * (n - 2) / 6; } // Funkcja do obliczania minimalnej liczby graczy int minimal_players_for_games(const vector<int>& games) { int players = 3; while (true) { long long total_games = 0; for (int game_count : games) { total_games += comb(players); } if (total_games >= games.size()) { return players; } players++; } } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> games(n); for (int i = 0; i < n; ++i) { cin >> games[i]; } cout << minimal_players_for_games(games) << endl; } return 0; } |