# Link
https://www.acmicpc.net/problem/2473
2473번: 세 용액
첫째 줄에는 전체 용액의 수 N이 입력된다. N은 3 이상 5,000 이하의 정수이다. 둘째 줄에는 용액의 특성값을 나타내는 N개의 정수가 빈칸을 사이에 두고 주어진다. 이 수들은 모두 -1,000,000,000 이상
www.acmicpc.net
# Code - C++
//
// BOJ
// ver.C++
//
// Created by GGlifer
//
// Open Source
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))
// Set up : Definitions
/* None */
// Set up : Global Variables
/* None */
// Set up : Functions Declaration
/* None */
int main()
{
// Set up : I/O
ios::sync_with_stdio(false);
cin.tie(nullptr);
// Set up : Input
int N; cin >> N;
long V[N];
for (int i=0; i<N; i++)
cin >> V[i];
// Process
sort(V, V+N);
vector<long> A = {V[0], V[1], V[2]};
long ans_val = V[0] + V[1] + V[2];
for (int i=0; i<N-2; i++) {
int s = i+1, e = N-1;
while (s < e) {
long tmp_val = V[i] + V[s] + V[e];
if (abs(ans_val) > abs(tmp_val)) {
A = {V[i], V[s], V[e]};
ans_val = tmp_val;
if (ans_val == 0) {
goto end;
}
}
(tmp_val > 0) ? e-- : s++;
}
} end:
// Control : Output
cout << A[0] << ' ' << A[1] << ' ' << A[2] << endl;
}
// Helper Functions
/* None */
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
[ Problem Solving :: 백준 ] 2456 / 나는 학급회장이다 (0) | 2021.11.25 |
---|---|
[ Problem Solving :: 백준 ] 1526 / 가장 큰 금민수 (0) | 2021.11.21 |
[ Problem Solving :: 백준 ] 11558 / The Game of Death (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 2698 / 인접한 비트의 개수 (0) | 2021.11.16 |
[ Problem Solving :: 백준 ] 14606 / 피자 (Small) (0) | 2021.11.16 |