#include <cstdio>
#include <algorithm>
#include <map>
constexpr int N = 500 * 1000;
struct Fish {
long long size;
int position;
};
long long fish[N];
int main() {
int n;
scanf("%d\n", &n);
std::map<long long, int> buckets;
for (int i = 0; i < n; ++i) {
scanf("%lld", &fish[i]);
buckets[fish[i]]++;
}
if (buckets.size() == 1) {
for (int i = 0; i < n; ++i) {
printf("N");
}
printf("\n");
return 0;
}
long long prefix = 0;
long long threshold = 1000 * 1000 * 1000 * 1000LL;
std::pair<long long, long long> previous = {0, 0};
int num = 0;
for (const auto& bucket : buckets) {
if (num == 1) {
threshold = previous.first;
}
if (prefix + previous.first * previous.second <= bucket.first) {
threshold = previous.first;
}
prefix += previous.first * previous.second;
previous = bucket;
num++;
}
for (int i = 0; i < n; ++i) {
if (fish[i] <= threshold) {
printf("N");
} else {
printf("T");
}
}
printf("\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 | #include <cstdio> #include <algorithm> #include <map> constexpr int N = 500 * 1000; struct Fish { long long size; int position; }; long long fish[N]; int main() { int n; scanf("%d\n", &n); std::map<long long, int> buckets; for (int i = 0; i < n; ++i) { scanf("%lld", &fish[i]); buckets[fish[i]]++; } if (buckets.size() == 1) { for (int i = 0; i < n; ++i) { printf("N"); } printf("\n"); return 0; } long long prefix = 0; long long threshold = 1000 * 1000 * 1000 * 1000LL; std::pair<long long, long long> previous = {0, 0}; int num = 0; for (const auto& bucket : buckets) { if (num == 1) { threshold = previous.first; } if (prefix + previous.first * previous.second <= bucket.first) { threshold = previous.first; } prefix += previous.first * previous.second; previous = bucket; num++; } for (int i = 0; i < n; ++i) { if (fish[i] <= threshold) { printf("N"); } else { printf("T"); } } printf("\n"); return 0; } |
English