#include <bits/stdc++.h>
using namespace std;
#define N 500000
int n, a;
struct Ryba{
long numer;
long long rozmiar;
long long prefiks;
long long trup;
};
bool aaa(Ryba a, Ryba b){
return a.rozmiar < b.rozmiar;
}
Ryba tab[N];
bool ans[N];
int main(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> a;
tab[i].numer = i;
tab[i].rozmiar = a;
}
sort(tab, tab+n, aaa);
tab[0].prefiks = tab[0].rozmiar;
tab[0].trup = tab[0].prefiks;
for(int i = 1; i < n; i++){
tab[i].prefiks = tab[i-1].prefiks + tab[i].rozmiar;
if (tab[i].rozmiar == tab[i-1].rozmiar && tab[i-1].trup <= tab[i].rozmiar){
tab[i].trup = tab[i-1].trup;
} else {
tab[i].trup = tab[i].prefiks;
}
}
//for(int i = 0; i < n; i++) cout << tab[i].rozmiar<< " ";
//cout << endl; for(int i = 0; i < n; i++) cout << tab[i].prefiks<< " ";
//cout << endl; for(int i = 0; i < n; i++) cout << tab[i].trup<< " ";
for(int i = 0; i < n; i++) ans[i] = false;
ans[ tab[n-1].numer ] = true;
for(int i = n-2; i >= 0; i--){
//cout << "Wielki rybosz " << tab[i].trup << " chce zjesc rybosza " << tab[i+1].rozmiar << endl;
if (tab[i].trup > tab[i+1].rozmiar ){
//cout << "I moze";
ans[tab[i].numer] = true;
} else break;
}
for(int i = 0; i < n; i++) {
if (ans[i])
cout << "T";
else
cout << "N";
}
}
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 | #include <bits/stdc++.h> using namespace std; #define N 500000 int n, a; struct Ryba{ long numer; long long rozmiar; long long prefiks; long long trup; }; bool aaa(Ryba a, Ryba b){ return a.rozmiar < b.rozmiar; } Ryba tab[N]; bool ans[N]; int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a; tab[i].numer = i; tab[i].rozmiar = a; } sort(tab, tab+n, aaa); tab[0].prefiks = tab[0].rozmiar; tab[0].trup = tab[0].prefiks; for(int i = 1; i < n; i++){ tab[i].prefiks = tab[i-1].prefiks + tab[i].rozmiar; if (tab[i].rozmiar == tab[i-1].rozmiar && tab[i-1].trup <= tab[i].rozmiar){ tab[i].trup = tab[i-1].trup; } else { tab[i].trup = tab[i].prefiks; } } //for(int i = 0; i < n; i++) cout << tab[i].rozmiar<< " "; //cout << endl; for(int i = 0; i < n; i++) cout << tab[i].prefiks<< " "; //cout << endl; for(int i = 0; i < n; i++) cout << tab[i].trup<< " "; for(int i = 0; i < n; i++) ans[i] = false; ans[ tab[n-1].numer ] = true; for(int i = n-2; i >= 0; i--){ //cout << "Wielki rybosz " << tab[i].trup << " chce zjesc rybosza " << tab[i+1].rozmiar << endl; if (tab[i].trup > tab[i+1].rozmiar ){ //cout << "I moze"; ans[tab[i].numer] = true; } else break; } for(int i = 0; i < n; i++) { if (ans[i]) cout << "T"; else cout << "N"; } } |
English