-
Notifications
You must be signed in to change notification settings - Fork 0
/
D1.cpp
81 lines (78 loc) · 1.8 KB
/
D1.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
long long ara[200005];
int main()
{
fastio;
long long t,n,m,i,j,cnt,mx,sum,x,cur;
cin>>t;
while(t--)
{
cin>>n>>m;
mx=0;
for(i=0;i<n;i++)
{
cur=0;
cnt=0;
cin>>x;
for(j=0;j<x;j++)
cin>>ara[j];
sort(ara,ara+x);
if(ara[0]>1)
{
cnt=2;
cur=1;
}
else if(ara[0]==1)
{
cnt=1;
cur=1;
}
for(j=1;j<x;j++)
{
if(cnt==2)
break;
if(ara[j]>ara[j-1]+1)
{
if(ara[j]==ara[j-1]+2)
{
cnt++;
cur=ara[j-1]+1;
}
else
{
if(cnt==1)
{
cnt++;
cur=ara[j-1]+1;
}
else
{
cnt=2;
cur=ara[j-1]+2;
}
}
}
// if(cnt==2)
// break;
}
if(cnt==0)
cur=ara[x-1]+2;
if(cnt==1)
cur=ara[x-1]+1;
//cout<<cur<<"\n";
mx=max(mx,cur);
}
//cout<<mx<<"\n";
if(m<=mx)
{
cout<<mx*(m+1)<<"\n";
continue;
}
sum=(mx+1)*mx;
sum+=(m*(m+1))/2-(mx*(mx+1))/2;
cout<<sum<<"\n";
}
return 0;
}