#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int LL;
constexpr LL N=5e5+7;
vector <LL> cnt[N];
pair<LL,LL> sum[N];
LL tab[N]; bool odp[N];
map <LL,LL> mapa;
int main()
{
ios_base::sync_with_stdio(0); cin.tie();
LL n, licz=0,d=0; cin>>n;
for(LL i=0;i!=n;i++) {
cin>>tab[i];
if(mapa.find(tab[i]) == mapa.end())
mapa[tab[i]] = d++;
cnt[mapa[tab[i]]].push_back(i);
}
sort(tab,tab+n);
sum[0]={tab[0],tab[0]};
for(LL i=1;i!=n;i++) {
if(tab[i] == sum[licz].second)
sum[licz].first += tab[i];
else {
sum[++licz]={tab[i],tab[i]};
if(licz) sum[licz].first += sum[licz-1].first;
}
}
sum[0].first = sum[0].second;
while(licz) {
if(sum[licz].first > sum[licz+1].second) {
LL w=mapa[sum[licz].second];
for(LL i=0;i!=cnt[w].size();i++)
odp[cnt[w][i]]=1;
} else
break;
licz--;
} for(LL i=0;i!=n;i++) {
if(odp[i]) 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 | #include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; typedef long long int LL; constexpr LL N=5e5+7; vector <LL> cnt[N]; pair<LL,LL> sum[N]; LL tab[N]; bool odp[N]; map <LL,LL> mapa; int main() { ios_base::sync_with_stdio(0); cin.tie(); LL n, licz=0,d=0; cin>>n; for(LL i=0;i!=n;i++) { cin>>tab[i]; if(mapa.find(tab[i]) == mapa.end()) mapa[tab[i]] = d++; cnt[mapa[tab[i]]].push_back(i); } sort(tab,tab+n); sum[0]={tab[0],tab[0]}; for(LL i=1;i!=n;i++) { if(tab[i] == sum[licz].second) sum[licz].first += tab[i]; else { sum[++licz]={tab[i],tab[i]}; if(licz) sum[licz].first += sum[licz-1].first; } } sum[0].first = sum[0].second; while(licz) { if(sum[licz].first > sum[licz+1].second) { LL w=mapa[sum[licz].second]; for(LL i=0;i!=cnt[w].size();i++) odp[cnt[w][i]]=1; } else break; licz--; } for(LL i=0;i!=n;i++) { if(odp[i]) cout<<'T'; else cout<<'N'; } return 0; } |
English