// Szymon Rusiecki (08.12.2021) #include <bits/stdc++.h> bool check (int it, long long *tab, int tab_len) { long long king = tab[it]; int i = 0; for (; i < it; ++i) { if (king > tab[i]) king += tab[i]; else return false; } for (i = it + 1; i < tab_len; ++i) { if (king > tab[i]) king += tab[i]; else return false; } return true; } void find (int it, long long *ori_tab, bool *bool_tab, long long *score_tab, int tab_len) { int starto = 0; int endo = tab_len - 1; int middo = starto; while (starto < endo) { if (ori_tab[it] == score_tab[middo]) break; else if (ori_tab[it] < score_tab[middo]) endo = middo; else if (ori_tab[it] > score_tab[middo]) starto = middo + 1; middo = (starto + endo) / 2; } bool_tab[middo] ? std::cout << 'T' : std::cout << 'N'; return; } int main () { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int n; std::cin >> n; auto *tab = new long long [n]; auto *temp_tab = new long long [n]; bool *might_be_king = new bool [n]; for (int i = 0; i < n; ++i) { long long input; std::cin >> input; tab[i] = input; temp_tab[i] = input; might_be_king[i] = false; } std::sort(temp_tab, temp_tab + n); int starto = 0; int endo = n - 1; int middo = (starto + endo) / 2; while (starto < endo) { (check(middo, temp_tab, n)) ? endo = middo : starto = middo + 1; middo = (starto + endo) / 2; } for (int i = middo; i < n; ++i) might_be_king[i] = true; for (int i = 0; i < n; ++i) find (i, tab, might_be_king, temp_tab, n); delete [] tab; delete [] temp_tab; delete [] might_be_king; 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | // Szymon Rusiecki (08.12.2021) #include <bits/stdc++.h> bool check (int it, long long *tab, int tab_len) { long long king = tab[it]; int i = 0; for (; i < it; ++i) { if (king > tab[i]) king += tab[i]; else return false; } for (i = it + 1; i < tab_len; ++i) { if (king > tab[i]) king += tab[i]; else return false; } return true; } void find (int it, long long *ori_tab, bool *bool_tab, long long *score_tab, int tab_len) { int starto = 0; int endo = tab_len - 1; int middo = starto; while (starto < endo) { if (ori_tab[it] == score_tab[middo]) break; else if (ori_tab[it] < score_tab[middo]) endo = middo; else if (ori_tab[it] > score_tab[middo]) starto = middo + 1; middo = (starto + endo) / 2; } bool_tab[middo] ? std::cout << 'T' : std::cout << 'N'; return; } int main () { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int n; std::cin >> n; auto *tab = new long long [n]; auto *temp_tab = new long long [n]; bool *might_be_king = new bool [n]; for (int i = 0; i < n; ++i) { long long input; std::cin >> input; tab[i] = input; temp_tab[i] = input; might_be_king[i] = false; } std::sort(temp_tab, temp_tab + n); int starto = 0; int endo = n - 1; int middo = (starto + endo) / 2; while (starto < endo) { (check(middo, temp_tab, n)) ? endo = middo : starto = middo + 1; middo = (starto + endo) / 2; } for (int i = middo; i < n; ++i) might_be_king[i] = true; for (int i = 0; i < n; ++i) find (i, tab, might_be_king, temp_tab, n); delete [] tab; delete [] temp_tab; delete [] might_be_king; return 0; } |