#include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //============================================= int n, mini; ll a[1000009], s[1000009], pre[1000009], naj[1000009]; //============================================= int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); s[i] = a[i]; } sort(s, s + n); mini = s[n - 1] + 1; for (ll i = 0, temp = s[0]; i < n; i++) { pre[i] = s[i]; if (temp == s[0]) { if (s[i] != s[0]) { pre[i] += i * s[0]; temp = 0; } } else pre[i] += pre[i - 1]; } naj[n - 1] = naj[n - 2] = s[n - 1] + 1; for (int i = n - 3; i >= 0; i--) naj[i] = max(naj[i + 1] - s[i + 1], s[i + 1] + 1); // for (int i = 0; i < n; i++) // printf("%5lld %5lld %5lld\n", s[i], naj[i], pre[i]); for (int i = 0; i < n; i++) if (pre[i] >= naj[i]) { mini = s[i]; break; } for (int i = 0; i < n; i++) if (a[i] >= mini) 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 55 56 57 58 | #include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //============================================= int n, mini; ll a[1000009], s[1000009], pre[1000009], naj[1000009]; //============================================= int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", &a[i]); s[i] = a[i]; } sort(s, s + n); mini = s[n - 1] + 1; for (ll i = 0, temp = s[0]; i < n; i++) { pre[i] = s[i]; if (temp == s[0]) { if (s[i] != s[0]) { pre[i] += i * s[0]; temp = 0; } } else pre[i] += pre[i - 1]; } naj[n - 1] = naj[n - 2] = s[n - 1] + 1; for (int i = n - 3; i >= 0; i--) naj[i] = max(naj[i + 1] - s[i + 1], s[i + 1] + 1); // for (int i = 0; i < n; i++) // printf("%5lld %5lld %5lld\n", s[i], naj[i], pre[i]); for (int i = 0; i < n; i++) if (pre[i] >= naj[i]) { mini = s[i]; break; } for (int i = 0; i < n; i++) if (a[i] >= mini) printf("T"); else printf("N"); printf("\n"); } //============================================= |