#include <bits/stdc++.h> #define ll long long #define f first #define s second using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); ll n; cin>>n; vector<pair<ll, ll>> tab; vector<bool> wyn(n); vector<ll> suf(n+1); for(ll i = 0; i < n; i++){ ll a; cin>>a; tab.push_back({a, i}); } sort(tab.begin(), tab.end()); for(ll i = n-1; i >= 0; i--){ suf[i] = max(tab[i].f, suf[i+1]-tab[i].f); } ll sum = 0; ll mini = 0; for(ll i = 0; i < n; i++){ //cout<<tab[i].f<<" "<<sum<<" "<<mini<<" "<<suf[i+1]<<'\n'; if(tab[i].f>mini&&tab[i].f+sum>suf[i+1]){ wyn[tab[i].s] = 1; } mini = max(tab[i].f-sum, mini); sum+=tab[i].f; } for(auto it:wyn) cout<<(it?'T':'N'); 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 | #include <bits/stdc++.h> #define ll long long #define f first #define s second using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); ll n; cin>>n; vector<pair<ll, ll>> tab; vector<bool> wyn(n); vector<ll> suf(n+1); for(ll i = 0; i < n; i++){ ll a; cin>>a; tab.push_back({a, i}); } sort(tab.begin(), tab.end()); for(ll i = n-1; i >= 0; i--){ suf[i] = max(tab[i].f, suf[i+1]-tab[i].f); } ll sum = 0; ll mini = 0; for(ll i = 0; i < n; i++){ //cout<<tab[i].f<<" "<<sum<<" "<<mini<<" "<<suf[i+1]<<'\n'; if(tab[i].f>mini&&tab[i].f+sum>suf[i+1]){ wyn[tab[i].s] = 1; } mini = max(tab[i].f-sum, mini); sum+=tab[i].f; } for(auto it:wyn) cout<<(it?'T':'N'); cout<<'\n'; return 0; } |