-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUntitled3.cpp
More file actions
51 lines (43 loc) · 778 Bytes
/
Copy pathUntitled3.cpp
File metadata and controls
51 lines (43 loc) · 778 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
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <algorithm>
#include<cstdlib>
#include<stdio.h>
using namespace std;
inline void scanint(int* x)
{
register char c = getchar_unlocked();
*x = 0;
for(; (c<48)||(c>57);c = getchar_unlocked());
for(; (c>47)&&(c<58);c = getchar_unlocked())
*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);
}
int main()
{
while(1)
{
int N;
scanint(&N);
if(N == 0) break;
int A[N];
for(int i = 0; i < N; i++)
scanint(&A[i]);
sort(A,A + N);
int ans = 0;
for(int i = 0; i < N-2; i++)
{
int I = 0;
int r = N-i-2;
while(I < r)
{
if(A[I] + A[r] < A[N-i-1])
{
ans += r - I;
I++;
}
else r--;
}
}
cout << ans << endl;
}
return 0;
}