#include <bits/stdc++.h> using namespace std; typedef long long ll; struct pr { int val; int it; }; bool comp(pr a, pr b) { return a.val < b.val; } int n; pr t[500002]; ll l[500002], r[500002]; bool res[500002]; void in() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &t[i].val); t[i].it = i; } sort(t + 1, t + n + 1, comp); /*for(int i = 1; i <= n; i++) cout << t[i].val << " "; cout << endl;*/ } void calcl() { ll ms = 0, mc = 0; for(int i = 1; i <= n; i++) { ms += max(0LL, ll(t[i].val + 1) - mc); mc += max(0LL, ll(t[i].val + 1) - mc) + ll(t[i].val); l[i] = ms; //cout << l[i] << endl; } } void calcr() { for(int i = n; i > 0; i--) r[i] = ll(t[i].val + 1) + max(0LL, r[i + 1] - ll(t[i].val + 1 + t[i].val)); /*cout << endl; for(int i = 1; i <= n; i++) cout << r[i] << endl; cout << endl;*/ } void calc() { ll sum = 0; for(int i = 1; i <= n; i++) { sum += ll(t[i].val); //cout << t[i].it << endl; res[t[i].it] = l[i - 1] <= t[i].val && sum >= r[i + 1]; } } void out() { for(int i = 1; i <= n; i++) putchar(res[i] ? 'T' : 'N'); } int main() { in(); calcl(); calcr(); calc(); out(); }
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 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> using namespace std; typedef long long ll; struct pr { int val; int it; }; bool comp(pr a, pr b) { return a.val < b.val; } int n; pr t[500002]; ll l[500002], r[500002]; bool res[500002]; void in() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &t[i].val); t[i].it = i; } sort(t + 1, t + n + 1, comp); /*for(int i = 1; i <= n; i++) cout << t[i].val << " "; cout << endl;*/ } void calcl() { ll ms = 0, mc = 0; for(int i = 1; i <= n; i++) { ms += max(0LL, ll(t[i].val + 1) - mc); mc += max(0LL, ll(t[i].val + 1) - mc) + ll(t[i].val); l[i] = ms; //cout << l[i] << endl; } } void calcr() { for(int i = n; i > 0; i--) r[i] = ll(t[i].val + 1) + max(0LL, r[i + 1] - ll(t[i].val + 1 + t[i].val)); /*cout << endl; for(int i = 1; i <= n; i++) cout << r[i] << endl; cout << endl;*/ } void calc() { ll sum = 0; for(int i = 1; i <= n; i++) { sum += ll(t[i].val); //cout << t[i].it << endl; res[t[i].it] = l[i - 1] <= t[i].val && sum >= r[i + 1]; } } void out() { for(int i = 1; i <= n; i++) putchar(res[i] ? 'T' : 'N'); } int main() { in(); calcl(); calcr(); calc(); out(); } |