Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <iostream>
#include <algorithm>
#include <string>
#include <climits>
using namespace std;
int main()
{
int n;
cin >> n;
int *fish = new int[n];
int *fish2 = new int[n];
long long *helper = new long long[n];
long long sum = 0;
for (int i=0;i<n;++i)
{
cin >> fish[i];
fish2[i] = fish[i];
sum += fish[i];
}
// a_i <= a_i+1
sort(fish,fish+n);
helper[0] = fish[0];
// b_i+1 = b_i + a_i+1
for (int i=1;i<n;++i)
{
helper[i] = helper[i-1]+fish[i];
}
// c_i+1 = (a_i+1 > a_i || c_i > a_i+1) ? b_i+1 : c_i
for (int i=1;i<n;++i)
{
if (fish[i] == fish[i-1] && helper[i-1] <= fish[i])
helper[i] = helper[i-1];
}
// d_i-1 = c_i-1 > a_i ? d_i : c_i-1
for (int i=n-2;i>=0;--i)
{
if (helper[i] > fish[i+1])
helper[i] = helper[i+1];
}
int minWeight = INT_MAX;
// min. waga suma, �eby sta� si� kr�lem
for (int i=0;i<n;++i)
{
if (helper[i] == sum)
{
minWeight = fish[i];
break;
}
}
for (int i=0;i<n;++i)
{
if (fish2[i] >= minWeight)
cout << "T";
else
cout << "N";
}
cout << endl;
delete[] fish;
delete[] fish2;
delete[] helper;
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 | #include <iostream> #include <algorithm> #include <string> #include <climits> using namespace std; int main() { int n; cin >> n; int *fish = new int[n]; int *fish2 = new int[n]; long long *helper = new long long[n]; long long sum = 0; for (int i=0;i<n;++i) { cin >> fish[i]; fish2[i] = fish[i]; sum += fish[i]; } // a_i <= a_i+1 sort(fish,fish+n); helper[0] = fish[0]; // b_i+1 = b_i + a_i+1 for (int i=1;i<n;++i) { helper[i] = helper[i-1]+fish[i]; } // c_i+1 = (a_i+1 > a_i || c_i > a_i+1) ? b_i+1 : c_i for (int i=1;i<n;++i) { if (fish[i] == fish[i-1] && helper[i-1] <= fish[i]) helper[i] = helper[i-1]; } // d_i-1 = c_i-1 > a_i ? d_i : c_i-1 for (int i=n-2;i>=0;--i) { if (helper[i] > fish[i+1]) helper[i] = helper[i+1]; } int minWeight = INT_MAX; // min. waga suma, �eby sta� si� kr�lem for (int i=0;i<n;++i) { if (helper[i] == sum) { minWeight = fish[i]; break; } } for (int i=0;i<n;++i) { if (fish2[i] >= minWeight) cout << "T"; else cout << "N"; } cout << endl; delete[] fish; delete[] fish2; delete[] helper; return 0; } |
English