#include <cstdio> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { int n; scanf("%d", &n); vector<int> t(n); for (int i = 0; i < n; i++) scanf("%d", &t[i]); vector<int> c = t; sort(c.begin(), c.end()); int j = (int)c.size()-1; long long s = 0; for (int i = 0; i < n; i++) s += c[i]; int ret = c.back()+1; for (int i = (int)c.size() - 1; i >= 1; i--) { if (c[0] >= c[i]) break; while(j > 0 && c[j] > c[i]) { s -= c[j]; j--; } if (i == (int)c.size() - 1 || s > c[i+1]) { ret = c[i]; } else break; } { char s[501013]; for (int i = 0; i < n; i++) if (t[i] >= ret) s[i] = 'T'; else s[i] = 'N'; s[n] = 0; puts(s); } 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 | #include <cstdio> #include <vector> #include <string> #include <algorithm> using namespace std; int main() { int n; scanf("%d", &n); vector<int> t(n); for (int i = 0; i < n; i++) scanf("%d", &t[i]); vector<int> c = t; sort(c.begin(), c.end()); int j = (int)c.size()-1; long long s = 0; for (int i = 0; i < n; i++) s += c[i]; int ret = c.back()+1; for (int i = (int)c.size() - 1; i >= 1; i--) { if (c[0] >= c[i]) break; while(j > 0 && c[j] > c[i]) { s -= c[j]; j--; } if (i == (int)c.size() - 1 || s > c[i+1]) { ret = c[i]; } else break; } { char s[501013]; for (int i = 0; i < n; i++) if (t[i] >= ret) s[i] = 'T'; else s[i] = 'N'; s[n] = 0; puts(s); } return 0; } |