80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define MAX_SIZE 500500
|
|
|
|
int N, M, T;
|
|
int A[1000], B[1000];
|
|
long long sumA[MAX_SIZE], sumB[MAX_SIZE];
|
|
|
|
int compare(const void* a, const void* b) {
|
|
long long x = *(long long*)a;
|
|
long long y = *(long long*)b;
|
|
|
|
if(x < y) return -1;
|
|
else if(x > y) return 1;
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
scanf("%d",&T);
|
|
|
|
scanf("%d",&N);
|
|
for(int i=0; i<N; i++) scanf("%d",&A[i]);
|
|
|
|
scanf("%d",&M);
|
|
for(int i=0; i<M; i++) scanf("%d",&B[i]);
|
|
|
|
int sumA_size = 0;
|
|
for(int i=0; i<N; i++) {
|
|
int currentSum = 0;
|
|
for(int j=i; j<N; j++) {
|
|
currentSum += A[j];
|
|
sumA[sumA_size++] = currentSum;
|
|
}
|
|
}
|
|
|
|
int sumB_size = 0;
|
|
for(int i=0; i<M; i++) {
|
|
int currentSum = 0;
|
|
for(int j=i; j<M; j++) {
|
|
currentSum += B[j];
|
|
sumB[sumB_size++] = currentSum;
|
|
}
|
|
}
|
|
|
|
qsort(sumA, sumA_size, sizeof(long long), compare);
|
|
qsort(sumB, sumB_size, sizeof(long long), compare);
|
|
|
|
int ptA = 0, ptB = sumB_size - 1;
|
|
long long ans = 0;
|
|
while(ptA < sumA_size && ptB >= 0) {
|
|
long long temp = sumA[ptA] + sumB[ptB];
|
|
|
|
if(temp != T) {
|
|
if(T > temp) ptA++;
|
|
else ptB--;
|
|
continue;
|
|
}
|
|
|
|
int same_count_A = 0;
|
|
int current_sumA = sumA[ptA];
|
|
while(ptA < sumA_size && sumA[ptA] == current_sumA) {
|
|
ptA++;
|
|
same_count_A++;
|
|
}
|
|
|
|
int same_count_B = 0;
|
|
int current_sumB = sumB[ptB];
|
|
while(ptB >= 0 && sumB[ptB] == current_sumB) {
|
|
ptB--;
|
|
same_count_B++;
|
|
}
|
|
|
|
ans += (long long)same_count_A * same_count_B;
|
|
}
|
|
|
|
printf("%lld\n",ans);
|
|
|
|
return 0;
|
|
} |