#include <bits/stdc++.h>
using namespace std;
queue <int> ryby_odp;
map <int, int> ryby;
map<int, int>::iterator strt;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
bool czy_krol;
int max=-1;
int suma_wagi;
int osobnik;
int n;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>osobnik;
ryby[osobnik]++;
ryby_odp.push(osobnik);
if(osobnik>max)
{
max=osobnik;
}
}
while(!ryby_odp.empty())
{
osobnik=ryby_odp.front();
ryby_odp.pop();
suma_wagi=osobnik;
czy_krol=false;
strt=ryby.begin();
suma_wagi=suma_wagi+(strt->first)*(strt->second);
strt=ryby.find(osobnik);
if(strt!=ryby.begin())
{
strt--;
for(;strt!=ryby.begin(); strt--)
{
suma_wagi=suma_wagi+(strt->first)*(strt->second);
if(suma_wagi>max)
{
czy_krol=true;
break;
}
}
if(suma_wagi>max)
{
czy_krol=true;
}
strt=ryby.find(osobnik);
if(suma_wagi>strt->first)
{
suma_wagi=suma_wagi+(strt->first)*(strt->second-1);
if(suma_wagi>max)
{
czy_krol=true;
}
}
strt++;
if(strt!=ryby.end())
{
for(; strt!=ryby.end(); strt++)
{
if(suma_wagi>strt->first)
{
suma_wagi=suma_wagi+(strt->first)*(strt->second);
if(suma_wagi>max)
{
czy_krol=true;
break;
}
}
}
}
}
if(czy_krol==true)
{
cout<<"T";
}
else
{
cout<<"N";
}
}
cout<<endl;
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #include <bits/stdc++.h> using namespace std; queue <int> ryby_odp; map <int, int> ryby; map<int, int>::iterator strt; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool czy_krol; int max=-1; int suma_wagi; int osobnik; int n; cin>>n; for(int i=0; i<n; i++) { cin>>osobnik; ryby[osobnik]++; ryby_odp.push(osobnik); if(osobnik>max) { max=osobnik; } } while(!ryby_odp.empty()) { osobnik=ryby_odp.front(); ryby_odp.pop(); suma_wagi=osobnik; czy_krol=false; strt=ryby.begin(); suma_wagi=suma_wagi+(strt->first)*(strt->second); strt=ryby.find(osobnik); if(strt!=ryby.begin()) { strt--; for(;strt!=ryby.begin(); strt--) { suma_wagi=suma_wagi+(strt->first)*(strt->second); if(suma_wagi>max) { czy_krol=true; break; } } if(suma_wagi>max) { czy_krol=true; } strt=ryby.find(osobnik); if(suma_wagi>strt->first) { suma_wagi=suma_wagi+(strt->first)*(strt->second-1); if(suma_wagi>max) { czy_krol=true; } } strt++; if(strt!=ryby.end()) { for(; strt!=ryby.end(); strt++) { if(suma_wagi>strt->first) { suma_wagi=suma_wagi+(strt->first)*(strt->second); if(suma_wagi>max) { czy_krol=true; break; } } } } } if(czy_krol==true) { cout<<"T"; } else { cout<<"N"; } } cout<<endl; return 0; } |
English