-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj2467.cpp
More file actions
40 lines (39 loc) · 738 Bytes
/
boj2467.cpp
File metadata and controls
40 lines (39 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
long long answer;
void input(){
cin >> n;
v.assign(n,0);
for(int i=0; i<n; i++){
cin >> v[i];
}
}
void solve(){
int a = 0,b=n-1;
int answer1=0, answer2=n-1;
answer=(long long)v[a]+(long long)v[b];
long long tmp = answer;
while(a<b){
tmp = (long long)v[a]+(long long)v[b];
if(abs(tmp)<abs(answer)){
answer = tmp;
answer1 = a;
answer2 = b;
}
if(tmp>0){
b--;
}
else{
a++;
}
}
cout << v[answer1] << " " << v[answer2];
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
input();
solve();
}