#include <algorithm>
#include <iostream>
#include <map>
#include <stdint.h>
#include <vector>
struct Data {
Data() {}
Data(int64_t weight, int count) : weight(weight), count(count) {}
int64_t weight{0};
int count{0};
int64_t sum{0};
bool operator<(const Data &other) { return weight < other.weight; }
};
int64_t process(const std::vector<int64_t> &v) {
std::map<int64_t, Data> m;
for (size_t i = 0; i < v.size(); ++i) {
m[v[i]].count++;
}
if (m.size() == 1) {
return std::numeric_limits<int64_t>::max();
}
std::vector<Data> sorted;
sorted.reserve(m.size());
for (auto &[k, d] : m) {
sorted.push_back(Data(k, d.count));
}
std::sort(sorted.begin(), sorted.end());
////////////////////////
for (size_t i = 0; i < sorted.size(); ++i) {
if (i == 0) {
sorted[i].sum = sorted[i].count * sorted[i].weight;
} else {
sorted[i].sum = sorted[i - 1].sum + (sorted[i].count * sorted[i].weight);
}
}
////////////////////////
// for (size_t i = 0; i < sorted.size(); ++i) {
// fprintf(stderr, "%ld %d %ld\n", sorted[i].weight, sorted[i].count,
// sorted[i].sum);
// }
////////////////////////
for (size_t i = sorted.size() - 1; i > 0; --i) {
if (sorted[i - 1].sum <= sorted[i].weight) {
return sorted[i].weight;
}
}
return sorted[1].weight;
}
int main() {
int N = 0;
std::cin >> N;
std::vector<int64_t> v(N);
for (int i = 0; i < N; ++i) {
std::cin >> v[i];
}
/////////////////////////
int64_t val = process(v);
for (const int64_t i : v) {
if (i >= val) {
std::cout << "T";
} else {
std::cout << "N";
}
}
std::cout << std::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 | #include <algorithm> #include <iostream> #include <map> #include <stdint.h> #include <vector> struct Data { Data() {} Data(int64_t weight, int count) : weight(weight), count(count) {} int64_t weight{0}; int count{0}; int64_t sum{0}; bool operator<(const Data &other) { return weight < other.weight; } }; int64_t process(const std::vector<int64_t> &v) { std::map<int64_t, Data> m; for (size_t i = 0; i < v.size(); ++i) { m[v[i]].count++; } if (m.size() == 1) { return std::numeric_limits<int64_t>::max(); } std::vector<Data> sorted; sorted.reserve(m.size()); for (auto &[k, d] : m) { sorted.push_back(Data(k, d.count)); } std::sort(sorted.begin(), sorted.end()); //////////////////////// for (size_t i = 0; i < sorted.size(); ++i) { if (i == 0) { sorted[i].sum = sorted[i].count * sorted[i].weight; } else { sorted[i].sum = sorted[i - 1].sum + (sorted[i].count * sorted[i].weight); } } //////////////////////// // for (size_t i = 0; i < sorted.size(); ++i) { // fprintf(stderr, "%ld %d %ld\n", sorted[i].weight, sorted[i].count, // sorted[i].sum); // } //////////////////////// for (size_t i = sorted.size() - 1; i > 0; --i) { if (sorted[i - 1].sum <= sorted[i].weight) { return sorted[i].weight; } } return sorted[1].weight; } int main() { int N = 0; std::cin >> N; std::vector<int64_t> v(N); for (int i = 0; i < N; ++i) { std::cin >> v[i]; } ///////////////////////// int64_t val = process(v); for (const int64_t i : v) { if (i >= val) { std::cout << "T"; } else { std::cout << "N"; } } std::cout << std::endl; return 0; } |
English