#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define m_p make_pair
#define fi first
#define se second
ll inf = 8000000000000000000;
ll mod = 30000;
const int maxn = 200003;
int main(){
ios_base::sync_with_stdio(0);
int n; cin>>n;
vector<pair<int, int>> t1(n);
ll s = 0;
for(int i = 0; i<n; i++){
ll a; cin>>a;
s += a;
t1[i] = {a, i};
}
sort(t1.begin(), t1.end());
if(t1[n-1].fi==t1[0].fi){
while(n--)
cout<<'N';
return 0;
}
vector<bool> dp(n), resy(n);
s -= t1[n-1].fi;
dp[n-1] = true;
resy[t1[n-1].se] = true;
for(int i = n-2; i>=0; i--){
if(t1[i].fi!=t1[0].fi && s>t1[i+1].fi){
resy[t1[i].se] = true;
s -= t1[i].fi;
}
else break;
}
for(auto i: resy){
if(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 42 43 44 45 46 47 48 49 50 | #include <bits/stdc++.h> using namespace std; #define ll long long #define p_b push_back #define m_p make_pair #define fi first #define se second ll inf = 8000000000000000000; ll mod = 30000; const int maxn = 200003; int main(){ ios_base::sync_with_stdio(0); int n; cin>>n; vector<pair<int, int>> t1(n); ll s = 0; for(int i = 0; i<n; i++){ ll a; cin>>a; s += a; t1[i] = {a, i}; } sort(t1.begin(), t1.end()); if(t1[n-1].fi==t1[0].fi){ while(n--) cout<<'N'; return 0; } vector<bool> dp(n), resy(n); s -= t1[n-1].fi; dp[n-1] = true; resy[t1[n-1].se] = true; for(int i = n-2; i>=0; i--){ if(t1[i].fi!=t1[0].fi && s>t1[i+1].fi){ resy[t1[i].se] = true; s -= t1[i].fi; } else break; } for(auto i: resy){ if(i) cout<<'T'; else cout<<'N'; } } |
English