We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a01d211 commit 78ba681Copy full SHA for 78ba681
1 file changed
박예진/10주차/260304.cpp
@@ -0,0 +1,42 @@
1
+//https://www.acmicpc.net/problem/2467
2
+
3
+#include <algorithm>
4
+#include <iostream>
5
6
+using namespace std;
7
8
+int N;
9
+int num[100001];
10
+int sum = 2000000001;
11
12
+int res1, res2;
13
+void binary_search() {
14
+ int left = 0;
15
+ int right = N - 1;
16
17
+ while (left < right) {
18
+ int plus = abs(num[left] + num[right]);
19
+ if (plus < sum) {
20
+ sum = plus;
21
+ res1 = num[left];
22
+ res2 = num[right];
23
+ }
24
+ if (num[left] + num[right] < 0)
25
+ left++;
26
+ else
27
+ right--;
28
29
+}
30
31
+int main() {
32
+ ios::sync_with_stdio(false);
33
+ cin.tie(NULL), cout.tie(NULL);
34
35
+ cin >> N;
36
+ for (int i = 0; i < N; i++) {
37
+ cin >> num[i];
38
39
40
+ binary_search();
41
+ cout << res1 << " " << res2;
42
0 commit comments