#include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif const int NMAX = 5e5 + 7; int n; int t[NMAX]; map<int, int> s; map<int, long long> m; long long suma; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) { cin >> t[i]; s[t[i]]++; m[t[i]] = t[i]; suma += t[i]; } auto it = s.begin(), last = it; it++; for (; it != s.end(); it++) { if (it->first < m[last->first]) { m[it->first] = m[last->first]; } else { long long masa = m[last->first]; if (masa == last->first) { masa += (long long) last->first * (long long) (last->second - 1); } masa += (long long) it->first * (long long) it->second; auto it2 = it; it2++; while (it2 != s.end() && masa > it2->first) { masa += (long long) it2->first * (long long) it2->second; it2++; } m[it->first] = masa; } last = it; } for (int i = 0; i < n; ++i) { if (m[t[i]] == suma) { cout << 'T'; } else { cout << '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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif const int NMAX = 5e5 + 7; int n; int t[NMAX]; map<int, int> s; map<int, long long> m; long long suma; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) { cin >> t[i]; s[t[i]]++; m[t[i]] = t[i]; suma += t[i]; } auto it = s.begin(), last = it; it++; for (; it != s.end(); it++) { if (it->first < m[last->first]) { m[it->first] = m[last->first]; } else { long long masa = m[last->first]; if (masa == last->first) { masa += (long long) last->first * (long long) (last->second - 1); } masa += (long long) it->first * (long long) it->second; auto it2 = it; it2++; while (it2 != s.end() && masa > it2->first) { masa += (long long) it2->first * (long long) it2->second; it2++; } m[it->first] = masa; } last = it; } for (int i = 0; i < n; ++i) { if (m[t[i]] == suma) { cout << 'T'; } else { cout << 'N'; } } return 0; } |