문제에 나온 테스트케이스를 참고하여 알고리즘을 구현했더니 오히려 틀렸다. 가장 간단하게 내림차순으로 정렬해서 세개씩 그룹짓는게 정답이다.
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
void input_milk(vector<int> &milk)
{
int N, i, cost;
cin >> N;
for (i = 0; i < N; i++)
{
cin >> cost;
milk.push_back(cost);
}
sort(milk.begin(), milk.end(), greater<>());
return;
}
void find_answer(vector<int>& milk)
{
int total = 0, temp_sum;
deque<int> group;
for (int i : milk)
{
group.push_back(i);
}
while (!group.empty())
{
temp_sum = 0;
if (group.size() > 2)
{
/*temp_sum += group.front();
group.pop_front();
group.pop_back();
temp_sum += group.back();
group.pop_back();
total += temp_sum;
cout << total << "\n";*/
temp_sum += group.front();
group.pop_front();
temp_sum += group.front();
group.pop_front();
group.pop_front();
total += temp_sum;
//cout << total << "\n";
}
else
{
total += group.front();
group.pop_front();
//cout << total << "\n";
}
}
cout << total << "\n";
return;
}
void find_answer2(vector<int>& milk)
{
int total = 0;
int i;
for (i = 0; i < milk.size(); i++)
{
if (i % 3 == 2)
{
continue;
}
total += milk[i];
}
cout << total << "\n";
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<int> milk;
input_milk(milk);
//find_answer(milk);
find_answer2(milk);
return 0;
}