#include <cstdio> #include <cstdlib> #include <cstring> #include <climits> int compar(const void *pa, const void *pb) { return *((int *) pa) - *((int *) pb); } int masa[500000]; int sort[500000]; long long sumy[500000]; int main(void) { int n, i, min = INT_MAX, eat = 0; long long sum, tot; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &masa[i]); memcpy(sort, masa, n * sizeof(masa[0])); qsort(sort, n, sizeof(sort[0]), compar); sumy[0] = sum = tot = sort[0]; for (i = 1; i < n; i++) { tot += sort[i]; if (!eat && sort[i] != sort[i - 1]) eat = 1; if (eat) sum = tot; sumy[i] = sum; } if (eat) { while (--i && sort[i] < sumy[i - 1]) ; min = sort[i]; } for (i = 0; i < n; i++) putchar(masa[i] < min ? 'N' : 'T'); putchar('\n'); 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 | #include <cstdio> #include <cstdlib> #include <cstring> #include <climits> int compar(const void *pa, const void *pb) { return *((int *) pa) - *((int *) pb); } int masa[500000]; int sort[500000]; long long sumy[500000]; int main(void) { int n, i, min = INT_MAX, eat = 0; long long sum, tot; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &masa[i]); memcpy(sort, masa, n * sizeof(masa[0])); qsort(sort, n, sizeof(sort[0]), compar); sumy[0] = sum = tot = sort[0]; for (i = 1; i < n; i++) { tot += sort[i]; if (!eat && sort[i] != sort[i - 1]) eat = 1; if (eat) sum = tot; sumy[i] = sum; } if (eat) { while (--i && sort[i] < sumy[i - 1]) ; min = sort[i]; } for (i = 0; i < n; i++) putchar(masa[i] < min ? 'N' : 'T'); putchar('\n'); return 0; } |