#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
if (n==1)
{
cout <<"T";
return 0;
}
vector <int>a(n);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
map <int, int>apom;
map <int, long long>masssum;
for (int i = 0; i < n; i++)
{
apom[a[i]]++;
}
auto it = apom.begin();
masssum[it->first] = ((it->first)*(it->second));
for (it++; it != apom.end(); it++)
{
auto itpom = it;
itpom--;
masssum[it->first] = masssum[(itpom)->first] + ((it->first)*(it->second));
}
auto it1 = masssum.begin();
int border = it1->first;
it1++;
while (it1!=masssum.end())
{
int lastkey = (it1->first);
long long lastsum = (it1->second);
it1++;
if ((it1!=masssum.end() )&& (lastsum<=(it1->first)) )
border = lastkey;
}
/*for (int i = 0; i < n; i++)
{
cout << apom[i]<< " ";
}*/
for (int i = 0; i < n; i++)
{
if (a[i]>border)
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 57 58 59 60 61 62 63 64 65 66 67 | #include <iostream> #include <vector> #include <string> #include <map> #include <algorithm> #include <fstream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (n==1) { cout <<"T"; return 0; } vector <int>a(n); for(int i=0;i<n;i++) { cin>>a[i]; } map <int, int>apom; map <int, long long>masssum; for (int i = 0; i < n; i++) { apom[a[i]]++; } auto it = apom.begin(); masssum[it->first] = ((it->first)*(it->second)); for (it++; it != apom.end(); it++) { auto itpom = it; itpom--; masssum[it->first] = masssum[(itpom)->first] + ((it->first)*(it->second)); } auto it1 = masssum.begin(); int border = it1->first; it1++; while (it1!=masssum.end()) { int lastkey = (it1->first); long long lastsum = (it1->second); it1++; if ((it1!=masssum.end() )&& (lastsum<=(it1->first)) ) border = lastkey; } /*for (int i = 0; i < n; i++) { cout << apom[i]<< " "; }*/ for (int i = 0; i < n; i++) { if (a[i]>border) cout<<'T'; else cout<<'N'; } return 0; } |
English