#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int tab[500007];
long long bicie[ 500007 ];
int odp[500008];
vector < pair<int, int> > wektor;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int ilosc, x;
cin>>ilosc;
for(int i=0; i<ilosc; ++i)
{
cin>>x;
wektor.push_back({x,i});
}
sort(wektor.begin(), wektor.end() );
bicie[0] = wektor[0].first;
tab[ 0 ] = 78;
if( ilosc > 2 ){
for( int i=0; i<wektor.size()-1; ++i)
{
if( i> 0 )
{
bicie[i] = bicie[i-1] + wektor[i].first;
if( wektor[i].first > wektor[i-1].first && bicie[i] > wektor[i+1].first )
{
tab[i] = 84;
}
else if( wektor[i].first > wektor[0].first && bicie[i] > wektor[i+1].first )
{
tab[i] = 84;
}
else {
tab[i] = 78;
}
}
}
}
if( wektor[wektor.size()-1].first > wektor[wektor.size()-2].first ){
tab[wektor.size()-1] = 84;
}
else if( wektor[wektor.size()-1].first > wektor[0].first) {
tab[wektor.size()-1] = 84;
}
else{
tab[wektor.size()-1] = 78;
}
odp[ wektor[ilosc-1].second ] = tab[ilosc-1];
for( int i = ilosc-1; i>=0; --i)
{
if( i < ilosc-1 ){
if( tab[i+1] == 78 ){
tab[i] = 78;
}
}
odp[ wektor[i].second ] = tab[i];
}
for(int i=0; i<ilosc; ++i)
{
cout << (char)odp[i];
}
}
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; int tab[500007]; long long bicie[ 500007 ]; int odp[500008]; vector < pair<int, int> > wektor; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int ilosc, x; cin>>ilosc; for(int i=0; i<ilosc; ++i) { cin>>x; wektor.push_back({x,i}); } sort(wektor.begin(), wektor.end() ); bicie[0] = wektor[0].first; tab[ 0 ] = 78; if( ilosc > 2 ){ for( int i=0; i<wektor.size()-1; ++i) { if( i> 0 ) { bicie[i] = bicie[i-1] + wektor[i].first; if( wektor[i].first > wektor[i-1].first && bicie[i] > wektor[i+1].first ) { tab[i] = 84; } else if( wektor[i].first > wektor[0].first && bicie[i] > wektor[i+1].first ) { tab[i] = 84; } else { tab[i] = 78; } } } } if( wektor[wektor.size()-1].first > wektor[wektor.size()-2].first ){ tab[wektor.size()-1] = 84; } else if( wektor[wektor.size()-1].first > wektor[0].first) { tab[wektor.size()-1] = 84; } else{ tab[wektor.size()-1] = 78; } odp[ wektor[ilosc-1].second ] = tab[ilosc-1]; for( int i = ilosc-1; i>=0; --i) { if( i < ilosc-1 ){ if( tab[i+1] == 78 ){ tab[i] = 78; } } odp[ wektor[i].second ] = tab[i]; } for(int i=0; i<ilosc; ++i) { cout << (char)odp[i]; } } |
English