#include<cstdio>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int t[500005];
int tc[500005];
long long n,lowersum,candidate,i,ip,fail;
int main(){
scanf("%d",&n);
for(i = 0; i<n ;i++){
scanf("%lld",&t[i]);
tc[i]=t[i];
}
t[n]=-1;
sort(t,t+n);
if(t[0]==t[n-1]){
for(i = 0; i<n ;i++){
printf("N");
}
}
else{
// minlower
i=0;
lowersum = t[0];
while(t[++i]==t[0]){
lowersum += t[0];
};
candidate = t[i];
lowersum += t[i];
for(i++;i<n;i++){
// printf("%d\n",lowersum);
if(t[i]>=lowersum){
candidate=t[i];
}
lowersum+=t[i];
}
for(int i = 0; i<n ;i++){
if(tc[i]<candidate)
printf("N");
else
printf("T");
}
}
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 43 44 45 46 47 48 49 50 51 52 53 | #include<cstdio> #include<algorithm> #include <bits/stdc++.h> using namespace std; int t[500005]; int tc[500005]; long long n,lowersum,candidate,i,ip,fail; int main(){ scanf("%d",&n); for(i = 0; i<n ;i++){ scanf("%lld",&t[i]); tc[i]=t[i]; } t[n]=-1; sort(t,t+n); if(t[0]==t[n-1]){ for(i = 0; i<n ;i++){ printf("N"); } } else{ // minlower i=0; lowersum = t[0]; while(t[++i]==t[0]){ lowersum += t[0]; }; candidate = t[i]; lowersum += t[i]; for(i++;i<n;i++){ // printf("%d\n",lowersum); if(t[i]>=lowersum){ candidate=t[i]; } lowersum+=t[i]; } for(int i = 0; i<n ;i++){ if(tc[i]<candidate) printf("N"); else printf("T"); } } return 0; } |
English