-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1253.cpp
43 lines (36 loc) · 859 Bytes
/
1253.cpp
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
41
42
43
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int ans;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int N;
cin >> N;
vector<int> v(N);
for(int i = 0; i < N; i++){
cin >> v[i];
}
sort(v.begin(), v.end());
for(int i = 0; i < N; i++){
int target = v[i];
int start = 0;
int end = N-1;
int sum = 0;
while (start < end){
sum = v[start] + v[end];
if(sum == target){
if(start != i && end != i){
ans++;
break;
}
else if(start == i) start++;
else if(end == i) end--;
}
else if(sum > target) end--;
else start++;
}
}
cout << ans;
return 0;
}