Notice
Recent Posts
Recent Comments
Link
안녕 세상아,
[c++/백준] 11508 2+1 세일 본문
https://www.acmicpc.net/problem/11508
11508번: 2+1 세일
KSG 편의점에서는 과일우유, 드링킹요구르트 등의 유제품을 '2+1 세일'하는 행사를 하고 있습니다. KSG 편의점에서 유제품 3개를 한 번에 산다면 그중에서 가장 싼 것은 무료로 지불하고 나머지 두
www.acmicpc.net
내림차순으로 정리한 후 3으로 나눈 나머지가 2이면 덧셈할 때 스킵해주면 된다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end(), greater<>());
int sum = 0;
for (int i = 0; i < v.size(); i++) {
if (i % 3 == 2) {
continue;
}
else
{
sum += v[i];
}
}
cout<<sum;
}'백준' 카테고리의 다른 글
| [c++/백준] 2630 색종이 만들기 (2) | 2023.06.21 |
|---|---|
| [c++/백준] 6603 로또 (0) | 2023.06.19 |
| [c++/백준] 18870 좌표 압축 (0) | 2023.06.16 |
| [c++/백준] 4963 섬의 개수 (bfs) (0) | 2023.06.15 |
| [c++/백준] 1012 유기농 배추 (0) | 2023.06.12 |