#include <iostream> #include <map> #include <iterator> #define undef 1000000001UL int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n; std::map<unsigned, unsigned> mapa; std::map<unsigned, unsigned>::iterator it, next; unsigned arr[n]; for(int i=0;i<n;i++) { std::cin >> arr[i]; mapa[arr[i]]++; } unsigned long long int cpt = 0, cur; unsigned min = undef, siz = mapa.size(); for(it = mapa.begin(); it != mapa.end();it++) { if(cpt) cur = it->first * it->second + cpt; else cur = it->first + cpt; next = std::next(it); if(next == mapa.end()) { if(siz > 1) if(min == undef) min = it->first; } else if(next->first < cur) { if(min == undef) min = it->first; } else min = undef; cpt += it->first * it->second; } //printf("%d\n", min); //if(!min) min = mapa.end()->first; for(int i=0;i<n;i++) { if(arr[i] >= min) std::cout << 'T'; else std::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 <map> #include <iterator> #define undef 1000000001UL int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n; std::cin >> n; std::map<unsigned, unsigned> mapa; std::map<unsigned, unsigned>::iterator it, next; unsigned arr[n]; for(int i=0;i<n;i++) { std::cin >> arr[i]; mapa[arr[i]]++; } unsigned long long int cpt = 0, cur; unsigned min = undef, siz = mapa.size(); for(it = mapa.begin(); it != mapa.end();it++) { if(cpt) cur = it->first * it->second + cpt; else cur = it->first + cpt; next = std::next(it); if(next == mapa.end()) { if(siz > 1) if(min == undef) min = it->first; } else if(next->first < cur) { if(min == undef) min = it->first; } else min = undef; cpt += it->first * it->second; } //printf("%d\n", min); //if(!min) min = mapa.end()->first; for(int i=0;i<n;i++) { if(arr[i] >= min) std::cout << 'T'; else std::cout << 'N'; } return 0; } |