#include <bits/stdc++.h> using namespace std; #define st first #define nd second typedef long long ll; const int MAX = 5e5 + 7; pair <int, int> t[MAX]; ll pref[MAX]; bool vis[MAX]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++){ cin >> t[i].st; t[i].nd = i; } sort(t, t+n); pref[0] = (ll)t[0].st; for(int i = 1; i < n; i++){ pref[i] = (ll)t[i].st + pref[i-1]; } for(int i = n-2; i >= 0; --i){ if(t[i].st == t[i+1].st) pref[i] = pref[i+1]; if(t[i].st == t[0].st) pref[i] = (ll)t[0].st; } int j = n-2; if(t[n-1].st > t[0].st) vis[t[n-1].nd] = true; while(pref[j] > t[j+1].st && j >= 0){ vis[t[j].nd] = true; j--; } for(int i = 0; i < n; i++){ if(vis[i]) 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 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second typedef long long ll; const int MAX = 5e5 + 7; pair <int, int> t[MAX]; ll pref[MAX]; bool vis[MAX]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++){ cin >> t[i].st; t[i].nd = i; } sort(t, t+n); pref[0] = (ll)t[0].st; for(int i = 1; i < n; i++){ pref[i] = (ll)t[i].st + pref[i-1]; } for(int i = n-2; i >= 0; --i){ if(t[i].st == t[i+1].st) pref[i] = pref[i+1]; if(t[i].st == t[0].st) pref[i] = (ll)t[0].st; } int j = n-2; if(t[n-1].st > t[0].st) vis[t[n-1].nd] = true; while(pref[j] > t[j+1].st && j >= 0){ vis[t[j].nd] = true; j--; } for(int i = 0; i < n; i++){ if(vis[i]) cout << "T"; else cout << "N"; } return 0; } |