// Example program #include <iostream> #include <algorithm> #define MAXN 500003 int n; long long a_old[MAXN]; long long a[MAXN]; long long last = 1000000005LL; bool can_be(int s_index) { long long cur_sum = a[s_index]; for (int i = 0; i < n; i++) { if (i != s_index) { if (a[i] >= cur_sum) { return false; } cur_sum += a[i]; } } return true; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); a_old[i] = a[i]; } std::sort(a, a+n); int b = 0, e = (n-1); while (b <= e) { int mid = (b + e) / 2; if (can_be(mid)) { last = a[mid]; e = mid - 1; } else { b = mid + 1; } } for (int i = 0; i < n; i++) { if (a_old[i] >= last) { printf("T"); } else { printf("N"); } } 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 | // Example program #include <iostream> #include <algorithm> #define MAXN 500003 int n; long long a_old[MAXN]; long long a[MAXN]; long long last = 1000000005LL; bool can_be(int s_index) { long long cur_sum = a[s_index]; for (int i = 0; i < n; i++) { if (i != s_index) { if (a[i] >= cur_sum) { return false; } cur_sum += a[i]; } } return true; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); a_old[i] = a[i]; } std::sort(a, a+n); int b = 0, e = (n-1); while (b <= e) { int mid = (b + e) / 2; if (can_be(mid)) { last = a[mid]; e = mid - 1; } else { b = mid + 1; } } for (int i = 0; i < n; i++) { if (a_old[i] >= last) { printf("T"); } else { printf("N"); } } printf("\n"); } |