#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
const int MOD=1e9+7;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int len, n, ans=0; cin >> len >> n;
priority_queue<pii, vector<pii>, greater<pii>> pq;
while(n--) {
int x, sum=len, pre=1; cin >> x;
vector<int> a(x);
for(int &p : a) cin >> p, sum-=p;
for(int p : a) {
if(p>sum) pq.push({pre+sum, pre+p-1});
pre+=p;
}
}
while(!pq.empty()) {
int l=pq.top().first, r=pq.top().second;
pq.pop();
while(!pq.empty() && pq.top().first<=r) r=max(r, pq.top().second), pq.pop();
ans+=r-l+1;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
120 ms |
8640 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
117 ms |
4512 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
5576 KB |
Output is correct |
2 |
Correct |
6 ms |
1568 KB |
Output is correct |
3 |
Correct |
8 ms |
1344 KB |
Output is correct |
4 |
Correct |
43 ms |
6536 KB |
Output is correct |
5 |
Correct |
13 ms |
3912 KB |
Output is correct |
6 |
Correct |
21 ms |
3840 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
24 ms |
4296 KB |
Output is correct |
9 |
Correct |
22 ms |
5304 KB |
Output is correct |
10 |
Correct |
37 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
5576 KB |
Output is correct |
2 |
Correct |
6 ms |
1568 KB |
Output is correct |
3 |
Correct |
8 ms |
1344 KB |
Output is correct |
4 |
Correct |
43 ms |
6536 KB |
Output is correct |
5 |
Correct |
13 ms |
3912 KB |
Output is correct |
6 |
Correct |
21 ms |
3840 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
24 ms |
4296 KB |
Output is correct |
9 |
Correct |
22 ms |
5304 KB |
Output is correct |
10 |
Correct |
37 ms |
6748 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
112 ms |
8532 KB |
Output is correct |
22 |
Correct |
17 ms |
2008 KB |
Output is correct |
23 |
Correct |
10 ms |
1800 KB |
Output is correct |
24 |
Correct |
43 ms |
6188 KB |
Output is correct |
25 |
Correct |
105 ms |
8560 KB |
Output is correct |
26 |
Correct |
37 ms |
5696 KB |
Output is correct |
27 |
Correct |
16 ms |
1996 KB |
Output is correct |
28 |
Correct |
101 ms |
8580 KB |
Output is correct |
29 |
Correct |
99 ms |
8592 KB |
Output is correct |
30 |
Correct |
37 ms |
3568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
120 ms |
8640 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
117 ms |
4512 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
40 ms |
5576 KB |
Output is correct |
22 |
Correct |
6 ms |
1568 KB |
Output is correct |
23 |
Correct |
8 ms |
1344 KB |
Output is correct |
24 |
Correct |
43 ms |
6536 KB |
Output is correct |
25 |
Correct |
13 ms |
3912 KB |
Output is correct |
26 |
Correct |
21 ms |
3840 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
24 ms |
4296 KB |
Output is correct |
29 |
Correct |
22 ms |
5304 KB |
Output is correct |
30 |
Correct |
37 ms |
6748 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
112 ms |
8532 KB |
Output is correct |
42 |
Correct |
17 ms |
2008 KB |
Output is correct |
43 |
Correct |
10 ms |
1800 KB |
Output is correct |
44 |
Correct |
43 ms |
6188 KB |
Output is correct |
45 |
Correct |
105 ms |
8560 KB |
Output is correct |
46 |
Correct |
37 ms |
5696 KB |
Output is correct |
47 |
Correct |
16 ms |
1996 KB |
Output is correct |
48 |
Correct |
101 ms |
8580 KB |
Output is correct |
49 |
Correct |
99 ms |
8592 KB |
Output is correct |
50 |
Correct |
37 ms |
3568 KB |
Output is correct |
51 |
Correct |
19 ms |
2220 KB |
Output is correct |
52 |
Correct |
100 ms |
9808 KB |
Output is correct |
53 |
Correct |
105 ms |
9620 KB |
Output is correct |
54 |
Correct |
24 ms |
3928 KB |
Output is correct |
55 |
Correct |
57 ms |
6924 KB |
Output is correct |
56 |
Correct |
37 ms |
6072 KB |
Output is correct |
57 |
Correct |
40 ms |
6536 KB |
Output is correct |
58 |
Correct |
113 ms |
9868 KB |
Output is correct |
59 |
Correct |
28 ms |
3544 KB |
Output is correct |
60 |
Correct |
39 ms |
4628 KB |
Output is correct |