-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF2003D1.cpp
37 lines (37 loc) · 875 Bytes
/
CF2003D1.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
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
istream &fin = cin;
ostream &fout = cout;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
fin >> T;
while (T--) {
size_t n;
ui m;
fin >> n >> m;
ui maxc2 = 0;
for (size_t i = 0; i < n; ++i) {
size_t c;
fin >> c;
vector<bool> vis(c + 5);
for (size_t i = 0; i < c; ++i) {
ui x;
fin >> x;
if (x < vis.size()) vis[x] = true;
}
ui c1 = 0;
for (; vis[c1]; ++c1);
ui c2 = c1 + 1;
for (; vis[c2]; ++c2);
maxc2 = max(c2, maxc2);
}
size_t l = min<size_t>(maxc2 + 1, m + 1);
fout << (uli)l * maxc2 + uli(l + m) * (m - l + 1) / 2 << '\n';
}
return 0;
}