File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change 1
- // Authored by : BaaaaaaaaaaarkingDog
1
+ // Authored by : HJPark
2
2
// Co-authored by : -
3
- // http://boj.kr/****************
3
+ // http://boj.kr/3b73c9a75b7c4d44be56fd6af6fc9fed
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
- int main (void ){
7
+ int n;
8
+ int a[100005 ];
9
+ int ans = 1e9 + 1 ;
10
+
11
+ int main (void ) {
8
12
ios::sync_with_stdio (0 );
9
13
cin.tie (0 );
10
-
11
- }
14
+
15
+ cin >> n;
16
+ for (int i = 0 ; i < n; i++) cin >> a[i];
17
+
18
+ int st = 0 , en = n - 1 ;
19
+ while (st < en) {
20
+ int val = a[st] + a[en];
8439
td>21
+ if (abs (val) < abs (ans)) ans = val;
22
+ if (val < 0 ) st++;
23
+ else en--;
24
+ }
25
+
26
+ cout << ans;
27
+ }
28
+
29
+ /*
30
+ 투포인터를 이용한 풀이
31
+ st, en이 입력된 배열의 양 끝을 가르킨다.
32
+ a[st]와 a[en]을 혼합한 특성값의 절대값이 ans의 절대값보다 낮을 경우 ans를 갱신한다.
33
+ 만약 혼합한 특성값이 0보다 작은 경우 st를 1만큼 증가시키고
34
+ 0보다 큰 경우 en을 1만큼 감소시킨다.
35
+ */
You can’t perform that action at this time.
0 commit comments