#include <bits/stdc++.h> #define ff first #define ss second using namespace std; int main() { int n; scanf("%d",&n); int m=INT_MAX; long long s=0; vector <pair<int,int>> t(n); for (int i=0; i<n; i++) { scanf("%d",&t[i].ff); t[i].ss=i; m=min(m,t[i].ff); s+=t[i].ff; } sort(t.begin(),t.end(),greater<pair<int,int>>()); vector <bool> w(n,0); if (t[0].ff!=m || n==1) { w[t[0].ss]=1; s-=t[0].ff; for (int i=1; i<n; i++) { if (t[i-1].ff>=s || t[i].ff==m) break; w[t[i].ss]=1; s-=t[i].ff; } } for (bool i: w) printf(i?"T":"N"); printf("\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 main() { int n; scanf("%d",&n); int m=INT_MAX; long long s=0; vector <pair<int,int>> t(n); for (int i=0; i<n; i++) { scanf("%d",&t[i].ff); t[i].ss=i; m=min(m,t[i].ff); s+=t[i].ff; } sort(t.begin(),t.end(),greater<pair<int,int>>()); vector <bool> w(n,0); if (t[0].ff!=m || n==1) { w[t[0].ss]=1; s-=t[0].ff; for (int i=1; i<n; i++) { if (t[i-1].ff>=s || t[i].ff==m) break; w[t[i].ss]=1; s-=t[i].ff; } } for (bool i: w) printf(i?"T":"N"); printf("\n"); return 0; } |