Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- bfs
- 너비우선탐색
- Stack
- 백준
- 브루트포스
- 컴공과
- 오에스
- OS
- cs
- c++
- 문제풀이
- 스택
- DP
- Operating System
- 컴공
- vector
- 정석학술정보관
- 알고리즘
- Computer science
- 북리뷰
- 그래프
- 정석
- 코딩
- 코테
- 개발
- 오퍼레이팅시스템
- 자료구조
- 구현
- 컴퓨터공학과
- coding
Archives
- Today
- Total
Little Jay
[C++] 백준 11508번 - 2 + 1 세일 본문
정렬을 잘 생각해보면 되는 문제
3개씩 묶고 제일 작은 것을 제외한 숫자를 제외하고
total에 더해주면 된다
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
vector<int> v(100001);
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end(), greater<int>());
int total = 0;
for (int i = 0; i < n; i++) {
total += v[i] + v[i + 1];
i += 2;
}
cout << total << '\n';
return 0;
}'알고리즘 > BOJ' 카테고리의 다른 글
| [C++] 백준 5430번 - AC (0) | 2021.08.23 |
|---|---|
| [C++] 백준 13241번 - 최소공배수 (0) | 2021.08.21 |
| [C++] 백준 2702번 - 초6 수학 (0) | 2021.08.21 |
| [C++] 백준 1912번 - 연속합 (0) | 2021.08.21 |
| [C++] 백준 1850번 - 최대공약수 (0) | 2021.08.21 |
Comments