#include <bits/stdc++.h> using namespace std; constexpr int N = 5*1e5+7; pair <long long, int> T[N]; bool M[N]; long long S[N]; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; long long x; for (int i=0; i<n; ++i) { cin>>x; T[i] = {x, i}; } sort(T, T+n); for (int i=1; i<=n; ++i) S[i] = S[i-1]+T[i-1].first; M[T[n-1].second] = true; for (int i=n-2; i>0; --i) { if (T[i].first>T[0].first && T[i].first+S[i-1]>T[i+1].first && M[T[i+1].second]) M[T[i].second] = true; } for (int i=0; i<n; ++i) { if (M[i]) cout<<'T'; else cout<<'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 | #include <bits/stdc++.h> using namespace std; constexpr int N = 5*1e5+7; pair <long long, int> T[N]; bool M[N]; long long S[N]; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; long long x; for (int i=0; i<n; ++i) { cin>>x; T[i] = {x, i}; } sort(T, T+n); for (int i=1; i<=n; ++i) S[i] = S[i-1]+T[i-1].first; M[T[n-1].second] = true; for (int i=n-2; i>0; --i) { if (T[i].first>T[0].first && T[i].first+S[i-1]>T[i+1].first && M[T[i+1].second]) M[T[i].second] = true; } for (int i=0; i<n; ++i) { if (M[i]) cout<<'T'; else cout<<'N'; } } |