๋ฌธ์
์ฝ๋
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 2e9+1
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vector<int>v(N);
for (int i = 0; i < N; i++) {
cin >> v[i];
}
int start = 0;
int end = N - 1;
int minValue = INF;
int check,ans;
while (start < end) {
check = abs(v[start] + v[end]);
if (check < minValue) {
minValue = check;
ans = v[start] + v[end];
}
if (v[start] + v[end] < 0) start++;
else end--;
}
cout << ans;
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 14938๋ฒ - ์๊ฐ๊ทธ๋ผ์ด๋ (0) | 2021.11.14 |
---|---|
[๋ฐฑ์ค,c++] 1439๋ฒ - ๋ค์ง๊ธฐ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14923๋ฒ - ๋ฏธ๋ก ํ์ถ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14920๋ฒ - 3n+1 ์์ด (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14916๋ฒ - ๊ฑฐ์ค๋ฆ๋ (0) | 2021.11.14 |
[๋ฐฑ์ค,c++] 14889๋ฒ - ์คํํธ์ ๋งํฌ (0) | 2021.11.14 |
๋๊ธ