#include <bits/stdc++.h>
using namespace std;
unsigned long long n,tab[500005],ryb[500005],pr[500005],x,naj,br,por;
int main()
{
scanf("%llu",&n);
for(int i=0; i<n; i++)
{
scanf("%llu",&tab[i]);
ryb[i] = tab[i];
if(tab[i]>naj)
naj=tab[i];
}
sort(tab, tab+n);
//cout<<naj;
pr[0]=tab[0];
for(int i=0; i<n; i++)
{
if(i!=0)
pr[i] = pr[i-1] + tab[i];
x = pr[i];
//cout<<x<<" ";
for(int j=i+1; j<n; j++)
{
if(x>tab[j])
x+=tab[j];
if(x>naj)
{
br=1;
break;
}
else if(x<=tab[j])
{
if(tab[i]>por)
por=tab[i];
break;
}
}
if(br==1)
break;
}
for(int i=0; i<n; i++)
{
if(ryb[i]>por)
cout<<"T";
else
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <bits/stdc++.h> using namespace std; unsigned long long n,tab[500005],ryb[500005],pr[500005],x,naj,br,por; int main() { scanf("%llu",&n); for(int i=0; i<n; i++) { scanf("%llu",&tab[i]); ryb[i] = tab[i]; if(tab[i]>naj) naj=tab[i]; } sort(tab, tab+n); //cout<<naj; pr[0]=tab[0]; for(int i=0; i<n; i++) { if(i!=0) pr[i] = pr[i-1] + tab[i]; x = pr[i]; //cout<<x<<" "; for(int j=i+1; j<n; j++) { if(x>tab[j]) x+=tab[j]; if(x>naj) { br=1; break; } else if(x<=tab[j]) { if(tab[i]>por) por=tab[i]; break; } } if(br==1) break; } for(int i=0; i<n; i++) { if(ryb[i]>por) cout<<"T"; else cout<<"N"; } return 0; } |
English