Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1599 Accepted Submission(s): 443
So, he needs to select two classmates as his teammates.
In this game, the IQ is very important, if you have low IQ you will WanTuo. Dudu's IQ is a given number k. We use an integer v[i] to represent the IQ of the ith classmate.
The sum of new two teammates' IQ must more than Dudu's IQ.
For some reason, Dudu don't want the two teammates comes from the same class.
Now, give you the status of classes, can you tell Dudu how many ways there are.
For each test case , the first line contains two integers, n and k, which means the number of class and the IQ of Dudu. n ( 0≤n≤1000 ), k( 0≤k<231 ).
Then, there are n classes below, for each class, the first line contains an integer m, which means the number of the classmates in this class, and for next m lines, each line contains an integer v[i], which means there is a person whose iq is v[i] in this class. m( 0≤m≤100 ), v[i]( 0≤v[i]<231 )
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N = 1005; const int M = 105; int v[M]; int v1[N*M]; int sum[N]; struct Node{ int num; int v[N]; }node[N]; int main(){ int tcase,n; int k; scanf("%d",&tcase); while(tcase--){ scanf("%d%d",&n,&k); int cnt = 1; for(int i=1;i<=n;i++){ scanf("%d",&node[i].num); sum[i] = sum[i-1]+node[i].num; for(int j=1;j<=node[i].num;j++){ scanf("%d",&v[j]); v1[cnt++] = v[j]; } sort(v+1,v+node[i].num+1); for(int j=1;j<=node[i].num;j++){ node[i].v[j] = v[j]; } } sort(v1+1,v1+cnt); long long ans = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=node[i].num;j++){ int v = node[i].v[j]; int pos1 = node[i].v+node[i].num+1 - lower_bound(node[i].v+1,node[i].v+1+node[i].num,k-v+1); int pos2 = v1+cnt - lower_bound(v1+1,v1+cnt,k-v+1); ans += pos2-pos1; } } printf("%lld\n",ans/2); } return 0; }