๋ฌธ์
14921๋ฒ: ์ฉ์ก ํฉ์ฑํ๊ธฐ
ํ์ต๋ ํํ์ฐ๊ตฌ์๋ ๋ค์ํ ์ฉ์ก์ ๋ณด์ ํ๊ณ ์๋ค. ๊ฐ ์ฉ์ก์ -100,000,000๋ถํฐ 100,000,000์ฌ์ด์ ํน์ฑ ๊ฐ์ ๊ฐ๋๋ฐ, ๊ฐ์ ์์ ๋ ์ฉ์ก์ ํผํฉํ๋ฉด, ๊ทธ ํน์ฑ๊ฐ์ ๋ ์ฉ์ก์ ํน์ฑ๊ฐ์ ํฉ์ด ๋๋ค. ๋น
www.acmicpc.net
์ฝ๋
#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 |
๋๊ธ