#include <bits/stdc++.h> struct Karas { int idx; uint64_t w; bool krul = false; uint64_t sum = 0; }; int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; std::vector<Karas> v(n); for(int i=0;i<n;i++) { uint64_t w; std::cin >> w; v[i] = {i,w}; } std::sort(v.begin(), v.end(), [](const Karas& a, const Karas& b){ return a.w > b.w; }); uint64_t sum = 0; for(auto it=v.rbegin(); it!=v.rend(); it++) { it->sum = sum + it->w; sum = it->sum; } std::map<int, uint64_t, std::greater<>> mp; for(int i=0;i<n;i++) { if(mp.count(v[i].w) == 0) { mp[v[i].w] = v[i].sum; //std::cout << "max " << v[i].w << " : " << v[i].sum << "\n"; } } uint64_t prev = 0; uint64_t peasant_weight = 0; for(auto it = mp.begin(); it != mp.end(); it++) { //std::cout << "prev = " << prev << " it->second = " << it->second << "\n"; //std::cout << "it->first = " << it->first << " mp.rbegin()->first = " << mp.rbegin()->first << "\n"; if(it->second <= prev && it->first != mp.rbegin()->first) { peasant_weight = it->first; break; } //std::cout << "peasant_weight = " << peasant_weight << "\n"; prev = it->first; } if(peasant_weight == 0) { if(mp.size() >= 2) { peasant_weight = mp.rbegin()->first; } else { peasant_weight = std::numeric_limits<uint64_t>::max(); } } std::sort(v.begin(), v.end(), [](const Karas& a, const Karas& b){ return a.idx < b.idx; }); for(int i=0;i<n;i++) { std::cout << (v[i].w > peasant_weight ? "T" : "N"); } 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #include <bits/stdc++.h> struct Karas { int idx; uint64_t w; bool krul = false; uint64_t sum = 0; }; int main() { std::ios_base::sync_with_stdio(0); int n; std::cin >> n; std::vector<Karas> v(n); for(int i=0;i<n;i++) { uint64_t w; std::cin >> w; v[i] = {i,w}; } std::sort(v.begin(), v.end(), [](const Karas& a, const Karas& b){ return a.w > b.w; }); uint64_t sum = 0; for(auto it=v.rbegin(); it!=v.rend(); it++) { it->sum = sum + it->w; sum = it->sum; } std::map<int, uint64_t, std::greater<>> mp; for(int i=0;i<n;i++) { if(mp.count(v[i].w) == 0) { mp[v[i].w] = v[i].sum; //std::cout << "max " << v[i].w << " : " << v[i].sum << "\n"; } } uint64_t prev = 0; uint64_t peasant_weight = 0; for(auto it = mp.begin(); it != mp.end(); it++) { //std::cout << "prev = " << prev << " it->second = " << it->second << "\n"; //std::cout << "it->first = " << it->first << " mp.rbegin()->first = " << mp.rbegin()->first << "\n"; if(it->second <= prev && it->first != mp.rbegin()->first) { peasant_weight = it->first; break; } //std::cout << "peasant_weight = " << peasant_weight << "\n"; prev = it->first; } if(peasant_weight == 0) { if(mp.size() >= 2) { peasant_weight = mp.rbegin()->first; } else { peasant_weight = std::numeric_limits<uint64_t>::max(); } } std::sort(v.begin(), v.end(), [](const Karas& a, const Karas& b){ return a.idx < b.idx; }); for(int i=0;i<n;i++) { std::cout << (v[i].w > peasant_weight ? "T" : "N"); } std::cout << "\n"; return 0; } |