#include <bits/stdc++.h> int n; bool rozne; int tab[500003]; int odp[500003]; bool sprawdz(int ktora) { long long masa = tab[ktora]; for (int i = 1; i < ktora; i++) { if (tab[i] < masa) masa += tab[i]; else return false; } for (int i = ktora + 1; i <= n; i++) if (tab[i] < masa) masa += tab[i]; else return false; return true; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &tab[i]); odp[i] = tab[i]; } std::sort(tab + 1, tab + n + 1); for (int i = 1; i < n; i++) if (tab[i] != tab[i + 1]) rozne = true; if (rozne == false) { for (int i = 1; i <= n; i++) printf("N"); printf("\n"); return 0; } int p = 0, k = n, s; while (p != k-1) { s = (p + k) / 2; if (sprawdz(s)) k = s; else p = s; } for (int i = 1; i <= n; i++) printf("%c", (odp[i] < tab[k] ? 'N' : 'T')); printf("\n"); }
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 | #include <bits/stdc++.h> int n; bool rozne; int tab[500003]; int odp[500003]; bool sprawdz(int ktora) { long long masa = tab[ktora]; for (int i = 1; i < ktora; i++) { if (tab[i] < masa) masa += tab[i]; else return false; } for (int i = ktora + 1; i <= n; i++) if (tab[i] < masa) masa += tab[i]; else return false; return true; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &tab[i]); odp[i] = tab[i]; } std::sort(tab + 1, tab + n + 1); for (int i = 1; i < n; i++) if (tab[i] != tab[i + 1]) rozne = true; if (rozne == false) { for (int i = 1; i <= n; i++) printf("N"); printf("\n"); return 0; } int p = 0, k = n, s; while (p != k-1) { s = (p + k) / 2; if (sprawdz(s)) k = s; else p = s; } for (int i = 1; i <= n; i++) printf("%c", (odp[i] < tab[k] ? 'N' : 'T')); printf("\n"); } |