#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid (l+r)/2 #define PI acos((ld)-1) #define BOOST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; int main(){ BOOST; int n, mn = INT_MAX; cin >> n; vii t(n); vll pref(n); vector<bool> king(n); for(int i=0; i<n; i++) cin >> t[i].fi, t[i].se = i, mn = min(mn, t[i].fi); sort(all(t)); pref[0] = t[0].fi; for(int i=1; i<n; i++) pref[i] = pref[i-1] + t[i].fi; king[t[n-1].se] = 1; for(int i=n-2; i>=0; i--){ if(king[t[i+1].se] && pref[i] > t[i+1].fi && t[i].fi != mn) king[t[i].se] = 1; } for(int i=0; i<n; i++) if(king[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 34 35 36 37 38 39 40 41 | #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define mid (l+r)/2 #define PI acos((ld)-1) #define BOOST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; int main(){ BOOST; int n, mn = INT_MAX; cin >> n; vii t(n); vll pref(n); vector<bool> king(n); for(int i=0; i<n; i++) cin >> t[i].fi, t[i].se = i, mn = min(mn, t[i].fi); sort(all(t)); pref[0] = t[0].fi; for(int i=1; i<n; i++) pref[i] = pref[i-1] + t[i].fi; king[t[n-1].se] = 1; for(int i=n-2; i>=0; i--){ if(king[t[i+1].se] && pref[i] > t[i+1].fi && t[i].fi != mn) king[t[i].se] = 1; } for(int i=0; i<n; i++) if(king[i]) cout << "T"; else cout << "N"; } |