#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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
115 ms |
13840 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
102 ms |
9512 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
6280 KB |
Output is correct |
2 |
Correct |
6 ms |
1624 KB |
Output is correct |
3 |
Correct |
6 ms |
1344 KB |
Output is correct |
4 |
Correct |
39 ms |
6496 KB |
Output is correct |
5 |
Correct |
13 ms |
3912 KB |
Output is correct |
6 |
Correct |
25 ms |
3852 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
24 ms |
4312 KB |
Output is correct |
9 |
Correct |
23 ms |
5308 KB |
Output is correct |
10 |
Correct |
38 ms |
6736 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
6280 KB |
Output is correct |
2 |
Correct |
6 ms |
1624 KB |
Output is correct |
3 |
Correct |
6 ms |
1344 KB |
Output is correct |
4 |
Correct |
39 ms |
6496 KB |
Output is correct |
5 |
Correct |
13 ms |
3912 KB |
Output is correct |
6 |
Correct |
25 ms |
3852 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
24 ms |
4312 KB |
Output is correct |
9 |
Correct |
23 ms |
5308 KB |
Output is correct |
10 |
Correct |
38 ms |
6736 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
115 ms |
8572 KB |
Output is correct |
22 |
Correct |
15 ms |
2016 KB |
Output is correct |
23 |
Correct |
10 ms |
1800 KB |
Output is correct |
24 |
Correct |
40 ms |
6152 KB |
Output is correct |
25 |
Correct |
103 ms |
8600 KB |
Output is correct |
26 |
Correct |
33 ms |
5760 KB |
Output is correct |
27 |
Correct |
13 ms |
1916 KB |
Output is correct |
28 |
Correct |
102 ms |
8528 KB |
Output is correct |
29 |
Correct |
100 ms |
8620 KB |
Output is correct |
30 |
Correct |
28 ms |
3572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
115 ms |
13840 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
102 ms |
9512 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
33 ms |
6280 KB |
Output is correct |
22 |
Correct |
6 ms |
1624 KB |
Output is correct |
23 |
Correct |
6 ms |
1344 KB |
Output is correct |
24 |
Correct |
39 ms |
6496 KB |
Output is correct |
25 |
Correct |
13 ms |
3912 KB |
Output is correct |
26 |
Correct |
25 ms |
3852 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
24 ms |
4312 KB |
Output is correct |
29 |
Correct |
23 ms |
5308 KB |
Output is correct |
30 |
Correct |
38 ms |
6736 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
115 ms |
8572 KB |
Output is correct |
42 |
Correct |
15 ms |
2016 KB |
Output is correct |
43 |
Correct |
10 ms |
1800 KB |
Output is correct |
44 |
Correct |
40 ms |
6152 KB |
Output is correct |
45 |
Correct |
103 ms |
8600 KB |
Output is correct |
46 |
Correct |
33 ms |
5760 KB |
Output is correct |
47 |
Correct |
13 ms |
1916 KB |
Output is correct |
48 |
Correct |
102 ms |
8528 KB |
Output is correct |
49 |
Correct |
100 ms |
8620 KB |
Output is correct |
50 |
Correct |
28 ms |
3572 KB |
Output is correct |
51 |
Correct |
16 ms |
2228 KB |
Output is correct |
52 |
Correct |
102 ms |
9832 KB |
Output is correct |
53 |
Correct |
103 ms |
9612 KB |
Output is correct |
54 |
Correct |
29 ms |
3932 KB |
Output is correct |
55 |
Correct |
57 ms |
6908 KB |
Output is correct |
56 |
Correct |
35 ms |
6124 KB |
Output is correct |
57 |
Correct |
48 ms |
6536 KB |
Output is correct |
58 |
Correct |
105 ms |
9880 KB |
Output is correct |
59 |
Correct |
28 ms |
3544 KB |
Output is correct |
60 |
Correct |
37 ms |
4612 KB |
Output is correct |