omingyu   4년 전

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <stdio.h>
#include <vector>

using namespace std;

priority_queue<int,vector<int>,greater<int>> qu;
vector<int> q;
int n, m, k;
int temp = 0;
int cnt = 1;
int mx = 0;
int answer;
int main()
{
cin >> n;

for (int i = 1; i <= n; i++)
{
cin >> m;
temp += m;
q.push_back(m);
}

sort(q.begin(), q.end());

printf("%0.0f\n", ( (double)temp /n));
printf("%d\n", q[(q.size() + 1) / 2 - 1]);

for (int i = 0; i < q.size()-1; i++)
{
if (q[i] == q[i + 1])
{
cnt++;
}
else
{
if (mx < cnt)
{
while (!qu.empty())
{
qu.pop();
}
mx = cnt;
qu.push(q[i]);
cnt = 1;
}
else if (mx == cnt)
{
qu.push(q[i]);
cnt = 1;
}
}
}

if (qu.size() > 1)
{
//cout << "qu.pop()-- " << qu.top() << endl;
qu.pop();
printf("%d\n", qu.top());
}
else
{
printf("%d\n", qu.top());
}
printf("%d\n", q[q.size() - 1] - q[0]);
}

댓글을 작성하려면 로그인해야 합니다.