#include <stdio.h> #include <algorithm> #include <cstdint> typedef int64_t int64; using namespace std; #define scan(args...) [&]{ return scanf(args); }(); const int max_size = 5e5; int main() { int n; char answer[max_size + 1]; pair<int, int> a[max_size]; scan("%d", &n); for (int i = 0; i < n; i++) { scan("%d", &a[i].first); a[i].second = i; } sort(a, a+n); int64 potrzeba[max_size]; potrzeba[n-1] = a[n-1].first + 1; for (int i = n-2; i >= 0; i--) potrzeba[i] = max((int64)a[i].first + 1, potrzeba[i+1]-a[i].first); int64 suma[max_size]; suma[0] = 0; for (int i = 1; i < n; i++) suma[i] = suma[i-1] + a[i-1].first; for (int i = 0; i < n; i++) { if (i > 0 && a[i].first == a[i-1].first) // Przepisujemy wynik answer[a[i].second] = answer[a[i-1].second]; else if (i == n-1) // Największa ryba, większa od drugiej co do wielkości answer[a[i].second] = 'T'; else if (a[i].first + suma[i] >= potrzeba[i+1]) answer[a[i].second] = 'T'; else answer[a[i].second] = 'N'; } answer[n] = '\0'; printf("%s\n", answer); 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 | #include <stdio.h> #include <algorithm> #include <cstdint> typedef int64_t int64; using namespace std; #define scan(args...) [&]{ return scanf(args); }(); const int max_size = 5e5; int main() { int n; char answer[max_size + 1]; pair<int, int> a[max_size]; scan("%d", &n); for (int i = 0; i < n; i++) { scan("%d", &a[i].first); a[i].second = i; } sort(a, a+n); int64 potrzeba[max_size]; potrzeba[n-1] = a[n-1].first + 1; for (int i = n-2; i >= 0; i--) potrzeba[i] = max((int64)a[i].first + 1, potrzeba[i+1]-a[i].first); int64 suma[max_size]; suma[0] = 0; for (int i = 1; i < n; i++) suma[i] = suma[i-1] + a[i-1].first; for (int i = 0; i < n; i++) { if (i > 0 && a[i].first == a[i-1].first) // Przepisujemy wynik answer[a[i].second] = answer[a[i-1].second]; else if (i == n-1) // Największa ryba, większa od drugiej co do wielkości answer[a[i].second] = 'T'; else if (a[i].first + suma[i] >= potrzeba[i+1]) answer[a[i].second] = 'T'; else answer[a[i].second] = 'N'; } answer[n] = '\0'; printf("%s\n", answer); return 0; } |