#include <bits/stdc++.h> #define ff first #define ss second using namespace std; int t[500007]; int s[500007]; int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; ++i){ cin >> t[i]; s[i]=t[i]; } sort(t,t+n); int km = t[n-1]; int w = 0; for (int i = 0; i < n-1; ++i)w+=t[i]; for (int i = n-2; i > 0; --i){ w-=t[i]; if(t[i]>t[0]){ if(t[i]+w >= km){ km=t[i]; } else{ break; } } } for (int i = 0; i < n; ++i){ if(s[i]>=km)cout << "T"; else cout << "N"; } 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 | #include <bits/stdc++.h> #define ff first #define ss second using namespace std; int t[500007]; int s[500007]; int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; ++i){ cin >> t[i]; s[i]=t[i]; } sort(t,t+n); int km = t[n-1]; int w = 0; for (int i = 0; i < n-1; ++i)w+=t[i]; for (int i = n-2; i > 0; --i){ w-=t[i]; if(t[i]>t[0]){ if(t[i]+w >= km){ km=t[i]; } else{ break; } } } for (int i = 0; i < n; ++i){ if(s[i]>=km)cout << "T"; else cout << "N"; } cout << "\n"; return 0; } |