# 수학 # 그리디 알고리즘
두 용액이라는 다른문제와 완전 동일한 문제다.
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#pragma warning(disable:4996)
using namespace std;
int s[1000005],mx,mi=1000000001,result[2];
bool cmp(int a, int b)
{
return abs(a) > abs(b);
}
int main()
{
scanf("%d", &mx);
for (int i = 0; i < mx; i++)
scanf("%d", &s[i]);
sort(s, s + mx, cmp);
for (int i = 0; i < mx - 1; i++)
if (abs(s[i] + s[i + 1]) < mi)
{
mi = abs(s[i] + s[i + 1]);
result[0] = s[i];
result[1] = s[i + 1];
}
printf("%d",result[0]+result[1]);
return 0;
}'IT > BOJ' 카테고리의 다른 글
| 백준(BOJ) 1572 중앙값 *** (0) | 2018.06.13 |
|---|---|
| 백준(BOJ) 14921 용액 합성하기 ** (0) | 2018.06.13 |
| 백준(BOJ) 14919 분포표 만들기 ** (0) | 2018.06.13 |
| 백준(BOJ) 15791 세진이의 미팅 ** (0) | 2018.06.05 |
| 백준(BOJ) 14621 나만 안되는 연애 ** (0) | 2018.06.03 |