백준
백준 소스코드 [C++] 14921 용액 합성하기
Hani_Levenshtein
2021. 3. 2. 06:38
14921번: 용액 합성하기
홍익대 화학연구소는 다양한 용액을 보유하고 있다. 각 용액은 -100,000,000부터 100,000,000사이의 특성 값을 갖는데, 같은 양의 두 용액을 혼합하면, 그 특성값은 두 용액의 특성값의 합이 된다. 당
www.acmicpc.net
백준 소스코드 [C++] 14921 용액 합성하기
#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;
int n;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n; v.resize(n);
for (int i = 0;i < n;i++) cin >> v[i];
int L = 0, R = n-1, here=abs(v[L]+v[R]),there;
int l = 0, r = n-1;
while (L<R) {
there = v[L] + v[R];
if (here > abs(there)) {
here = abs(there);
l = L, r = R;
}
if (there < 0) L++;
else R--;
}
cout << v[l] + v[r];
return 0;
}