11508번: 2+1 세일
KSG 편의점에서는 과일우유, 드링킹요구르트 등의 유제품을 '2+1 세일'하는 행사를 하고 있습니다. KSG 편의점에서 유제품 3개를 한 번에 산다면 그중에서 가장 싼 것은 무료로 지불하고 나머지 두
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <vector>
bool compae(int i, int j) {
return j < i;
}
int main() {
int n;
std::cin >> n;
std::vector<int> lst(n);
int tmp = 0;
for (int i = 0; i < n; i++) {
std::cin >> tmp;
lst.push_back(tmp);
}
std::sort(lst.begin(), lst.end(), compae);
int howmuch = 0;
for (int i = 0; i < n; i++) {
if (i % 3 != 2) {
howmuch += lst[i];
}
}
std::cout << howmuch << std::endl;
return 0;
}
'Computer Science > C++' 카테고리의 다른 글
백준 C++ | #8 BOJ3048 개미 C++ 문제 풀이 (0) | 2022.08.06 |
---|---|
백준 C++ | #7 BOJ1018 체스판 다시 칠하기 C++ 문제 풀이 (0) | 2022.08.05 |
백준 C++ | #5 BOJ1427 소트인사이드 C++ 문제 풀이 (0) | 2022.07.28 |
백준 C++ | #4 BOJ 11399 ATM 문제 풀이 (0) | 2022.07.28 |
백준 C++ | #3 BOJ1546 평균 C++ 풀이 (0) | 2022.07.27 |