// Created by Michal Kowalski on 08/12/2021. // #include <iostream> #include <algorithm> #include <vector> int N; long long S[500005]; bool O[500005]; int main(int argc, const char * argv[]) { scanf("%d",&N); std::vector<std::pair<long long, int>> V; V.reserve(N); for (int x=0;x<N;++x) { int w; scanf("%d",&w); V.push_back({(long long)w,x}); } std::sort(V.begin(), V.end()); S[0] = V[0].first; S[N] = 0; for (int i = 1;i<N;++i) { S[i] = (long long)S[i-1] + (long long)V[i].first; } for (int i=N-1;i>=0;--i) { if (V[i].first > V[0].first) { if (i == N) O[V[i].second]=true; else { if (S[i] > V[i+1].first) O[V[i].second] = true; else break; } } else { break; } } for (int i=0;i<N;++i) printf("%s",O[i]?"T":"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 | // Created by Michal Kowalski on 08/12/2021. // #include <iostream> #include <algorithm> #include <vector> int N; long long S[500005]; bool O[500005]; int main(int argc, const char * argv[]) { scanf("%d",&N); std::vector<std::pair<long long, int>> V; V.reserve(N); for (int x=0;x<N;++x) { int w; scanf("%d",&w); V.push_back({(long long)w,x}); } std::sort(V.begin(), V.end()); S[0] = V[0].first; S[N] = 0; for (int i = 1;i<N;++i) { S[i] = (long long)S[i-1] + (long long)V[i].first; } for (int i=N-1;i>=0;--i) { if (V[i].first > V[0].first) { if (i == N) O[V[i].second]=true; else { if (S[i] > V[i+1].first) O[V[i].second] = true; else break; } } else { break; } } for (int i=0;i<N;++i) printf("%s",O[i]?"T":"N"); return 0; } |