문제접근![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
비싼 유제품의 가격을 할인 받는게 효율
•
내림차순으로 정렬하고 3개씩 묶어서 할인 받는 제품 선택
놓쳤던 부분![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
코드![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
2416 KB
16 ms
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
int n;
vector<int> food;
long long answer = 0;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
food.resize(n);
for (int i = 0; i < n; i++)
cin >> food[i];
sort(food.begin(), food.end(), greater<>());
for (unsigned int i = 0; i < food.size(); i++)
{
if ((i + 1) % 3 == 0)
continue ;
answer += food[i];
}
cout << answer;
return (0);
}
C++
복사