-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUMFOUR.c
70 lines (69 loc) · 1.06 KB
/
SUMFOUR.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#define MAX 10000005
#define MAX2 4005
#define ll long long int
using namespace std;
int va[MAX2],vb[MAX2],vc[MAX2],vd[MAX2],vp1[2*MAX],vp2[2*MAX];
int vt[2][2*MAX];
int main()
{
int n,tmp,s1,s2;
cin>>n;
int a,b,c,d;
for(int i=0;i<n;++i)
{
scanf("%d %d %d %d",&va[i],&vb[i],&vc[i],&vd[i]);
}
tmp=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
vp1[tmp++]=va[i]+vb[j];
}
}
s1=tmp;
tmp=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
vp2[tmp++]=-(vc[i]+vd[j]);
}
}
s2=tmp;
sort(vp1,vp1+s1);
sort(vp2,vp2+s2);
int cnt = 1;
int i=0;
int s3;
tmp = 0;
vp1[s1] = vp1[s1-1] + 1;
for(i=1;i<=s1;++i)
{
if(vp1[i] == vp1[i-1])
cnt++;
else {
vt[1][tmp] = vp1[i-1];
vt[2][tmp++] = cnt;
cnt = 1;
}
}
s3=tmp;
long long int sum=0;
int j=0;
i=0;
while(i < s3 && j < s2)
{
if(vt[1][i] > vp2[j])
j++;
else if(vt[1][i] < vp2[j])
i++;
else
{
sum += vt[2][i];
j++;
}
}
cout<<sum<<endl;
}