#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int WyszukiwanieBinarne(int liczba_sumow, int tab[]) {
int poczatek=0, koniec=liczba_sumow-1;
while (poczatek<koniec)
{
int srodek=(poczatek+koniec)/2;
long long suma=tab[srodek];
int warunek=0;
//cout << poczatek << " " << koniec << " " << srodek << "\n";
for (int j=0; j<liczba_sumow; j++)
{
if (j!=srodek)
{
if (suma>tab[j])
suma+=tab[j];
else
warunek=1;
//cout << suma << " " << warunek << " ";
}
}
//cout << "\n";
if (warunek==0)
koniec=srodek;
else if (warunek==1)
poczatek=srodek+1;
}
return tab[poczatek];
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int tablica[n], dowynikow[n];
for (int i=0; i<n; i++)
{
int waga_suma;
cin >> waga_suma;
tablica[i]=waga_suma;
dowynikow[i]=waga_suma;
}
sort(tablica, tablica+n);
int wynik=WyszukiwanieBinarne(n, tablica);
//cout << wynik << "\n";
for (int g=0; g<n; g++)
{
if (dowynikow[g]>wynik)
cout << "T";
else if (dowynikow[g]==wynik&&dowynikow[g]!=tablica[0])
cout << "T";
else
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 | #include <iostream> #include <bits/stdc++.h> using namespace std; int WyszukiwanieBinarne(int liczba_sumow, int tab[]) { int poczatek=0, koniec=liczba_sumow-1; while (poczatek<koniec) { int srodek=(poczatek+koniec)/2; long long suma=tab[srodek]; int warunek=0; //cout << poczatek << " " << koniec << " " << srodek << "\n"; for (int j=0; j<liczba_sumow; j++) { if (j!=srodek) { if (suma>tab[j]) suma+=tab[j]; else warunek=1; //cout << suma << " " << warunek << " "; } } //cout << "\n"; if (warunek==0) koniec=srodek; else if (warunek==1) poczatek=srodek+1; } return tab[poczatek]; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int tablica[n], dowynikow[n]; for (int i=0; i<n; i++) { int waga_suma; cin >> waga_suma; tablica[i]=waga_suma; dowynikow[i]=waga_suma; } sort(tablica, tablica+n); int wynik=WyszukiwanieBinarne(n, tablica); //cout << wynik << "\n"; for (int g=0; g<n; g++) { if (dowynikow[g]>wynik) cout << "T"; else if (dowynikow[g]==wynik&&dowynikow[g]!=tablica[0]) cout << "T"; else cout << "N"; } return 0; } |
English