-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1253.cpp
More file actions
42 lines (34 loc) · 729 Bytes
/
1253.cpp
File metadata and controls
42 lines (34 loc) · 729 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
41
42
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int lld;
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio();
lld N, A[2010];
cin >> N;
for(int i=0; i<N; i++) cin >> A[i];
sort(A, A+N);
int cnt = 0;
for(int i=0; i<N; i++){
if(N<=2) break;
int a=0, b=N-1;
while(true){
if(a==i) a++;
if(b==i) b--;
lld sum = A[a]+A[b];
if(a>=b) break;
if(sum == A[i]){
cnt++;
break;
}else if(sum > A[i]){
b--;
}else{
a++;
}
}
}
cout << cnt;
}