#include "bits/stdc++.h" using namespace std; vector <pair<long long int,int>> m; int wyniki[500007] = {0}; vector <long long int> s; vector <long long int> w; bool porownaj(const pair<int,int> &a, const pair<int,int> &b) { return (a.first < b.first); } int main() { int n; long long int o = 0; long long int a; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a; o+=a; m.push_back(make_pair(a, i)); } sort(m.begin(), m.end(), porownaj); w.push_back(0LL); s.push_back(m[0].first); for (int i = 1; i < n; i++) { if (m[i-1].first == m[i].first) w.push_back(w[i-1]); else w.push_back(s[i-1]+m[i].first); s.push_back(s[i-1]+m[i].first); } int j = n-2; while (1) { if (w[j] <= m[j+1].first) break; j--; } for (int i = 0; i < n; i++) { if (i > j) wyniki[m[i].second]++; } for (int i = 0; i < n; i++) { if (wyniki[i] > 0 && o != (m[i].first*n)) cout << 'T'; else cout << 'N'; } exit(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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include "bits/stdc++.h" using namespace std; vector <pair<long long int,int>> m; int wyniki[500007] = {0}; vector <long long int> s; vector <long long int> w; bool porownaj(const pair<int,int> &a, const pair<int,int> &b) { return (a.first < b.first); } int main() { int n; long long int o = 0; long long int a; ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a; o+=a; m.push_back(make_pair(a, i)); } sort(m.begin(), m.end(), porownaj); w.push_back(0LL); s.push_back(m[0].first); for (int i = 1; i < n; i++) { if (m[i-1].first == m[i].first) w.push_back(w[i-1]); else w.push_back(s[i-1]+m[i].first); s.push_back(s[i-1]+m[i].first); } int j = n-2; while (1) { if (w[j] <= m[j+1].first) break; j--; } for (int i = 0; i < n; i++) { if (i > j) wyniki[m[i].second]++; } for (int i = 0; i < n; i++) { if (wyniki[i] > 0 && o != (m[i].first*n)) cout << 'T'; else cout << 'N'; } exit(0); } |