Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
911 B
1
Indexable
Never
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int mas[101];
	int k = n / 3;
	int a, b, c;
	if (n % 3 == 0) {
		a = n / 3;
		b = a;
		c = a;
	}
	if (n % 3 == 1) {
		a = n / 3 + 1;
		b = n / 3;
		c = b;
	}
	if (n % 3 == 2) {
		a = n / 3 + 1;
		b = n / 3 + 1;
		c = n / 3;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n-1; j++)
		{
			if (mas[j] > mas[j + 1]) {
				int tmp = mas[j + 1];
				mas[j + 1] = mas[j];
				mas[j] = tmp;
			}
		}
	}
	int r1 = 0, r2 = 0, r3 = 0;
	for (int i = 0; i < c; i++)
	{
		r3 += mas[i];
		//cout << mas[i] << " ";
	}
	for (int i = c; i < c+b; i++)
	{
		r2 += mas[i];
	//	cout << mas[i] << " ";
	}
	for (int i = c+b; i <n; i++)
	{
		r1 += mas[i];
	//	cout << mas[i] << " ";
	}
	cout << r1 / a << " " << r2 / b << " " << r3 / c; 
}