#include <bits/stdc++.h>
#define f first
#define s second
#define add push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
const int N = 500'005;
pint T[N];
ll sp[N];
bool potencjal[N];
char odp[N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,j;
bool ok;
cin >> n;
for(int i=0; i<n; i++)
{
cin >> T[i].f;
T[i].s=i;
}
sort(T, T+n);
sp[0]=T[0].f;
for(int i=1; i<n; i++) sp[i]=sp[i-1]+T[i].f;
j=0;
while(j<n && T[j].f==T[0].f) j++;
if(j<n) potencjal[n-1]=1;
for(; j<n-1; j++)
{
if(sp[j] > T[j+1].f) potencjal[j]=1;
}
ok=1;
for(int i=n-1; i>=0; i--)
{
if(!potencjal[i]) ok=0;
if(ok) odp[T[i].s] = 'T';
else odp[T[i].s] = 'N';
}
for(int i=0; i<n; i++)
cout << odp[i];
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 | #include <bits/stdc++.h> #define f first #define s second #define add push_back using namespace std; typedef long long ll; typedef pair<int,int> pint; const int N = 500'005; pint T[N]; ll sp[N]; bool potencjal[N]; char odp[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,j; bool ok; cin >> n; for(int i=0; i<n; i++) { cin >> T[i].f; T[i].s=i; } sort(T, T+n); sp[0]=T[0].f; for(int i=1; i<n; i++) sp[i]=sp[i-1]+T[i].f; j=0; while(j<n && T[j].f==T[0].f) j++; if(j<n) potencjal[n-1]=1; for(; j<n-1; j++) { if(sp[j] > T[j+1].f) potencjal[j]=1; } ok=1; for(int i=n-1; i>=0; i--) { if(!potencjal[i]) ok=0; if(ok) odp[T[i].s] = 'T'; else odp[T[i].s] = 'N'; } for(int i=0; i<n; i++) cout << odp[i]; return 0; } |
English