#include <bits/stdc++.h>
using namespace std;
using pi = pair<int,int>;
int l,r,in,n,ans=0;
int qs[500005]={};
vector<pi> ep;
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin >> l >> r;
qs[0]=0;
for(int i=0;i<r;i++){
cin >> n;
for(int j=1;j<=n;j++){
cin >> qs[j];
qs[j]+=qs[j-1];
}
//qs[n+1]=qs[n];
for(int j=1;j<=n;j++){
//gen ep
int sp=qs[j-1],sn=qs[n]-qs[j],val=qs[j]-qs[j-1];
int L=val,M=l-sn-sp;
//cout << '=' << L << ' ' << M << endl;
if(M-L+1 > L)continue;
ep.push_back({M-L+1+sp,1});
ep.push_back({L+1+sp,-1});
}
}
sort(ep.begin(),ep.end());
ep.push_back({l,-9999});
int block=0;
for(int i=0,j=ep.size()-1;i<j;i++){
auto[indx,v]=ep[i];
//cout << indx << ' ' << v << ' ' << endl;
block+=v;
if(block>=1 && (ep[i+1]).first > indx){
ans+=((ep[i+1]).first - indx);
}
}
cout << ans;
return 0;
}
/*
11 3
2 2 3
1 7
2 4 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
119 ms |
13800 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
121 ms |
9424 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5696 KB |
Output is correct |
2 |
Correct |
15 ms |
1300 KB |
Output is correct |
3 |
Correct |
9 ms |
1132 KB |
Output is correct |
4 |
Correct |
69 ms |
5840 KB |
Output is correct |
5 |
Correct |
34 ms |
3272 KB |
Output is correct |
6 |
Correct |
54 ms |
3532 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
35 ms |
3248 KB |
Output is correct |
9 |
Correct |
28 ms |
5300 KB |
Output is correct |
10 |
Correct |
61 ms |
5968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5696 KB |
Output is correct |
2 |
Correct |
15 ms |
1300 KB |
Output is correct |
3 |
Correct |
9 ms |
1132 KB |
Output is correct |
4 |
Correct |
69 ms |
5840 KB |
Output is correct |
5 |
Correct |
34 ms |
3272 KB |
Output is correct |
6 |
Correct |
54 ms |
3532 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
35 ms |
3248 KB |
Output is correct |
9 |
Correct |
28 ms |
5300 KB |
Output is correct |
10 |
Correct |
61 ms |
5968 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
130 ms |
8632 KB |
Output is correct |
22 |
Correct |
34 ms |
2004 KB |
Output is correct |
23 |
Correct |
15 ms |
1876 KB |
Output is correct |
24 |
Correct |
56 ms |
5896 KB |
Output is correct |
25 |
Correct |
136 ms |
8508 KB |
Output is correct |
26 |
Correct |
43 ms |
5708 KB |
Output is correct |
27 |
Correct |
18 ms |
2000 KB |
Output is correct |
28 |
Correct |
193 ms |
8672 KB |
Output is correct |
29 |
Correct |
136 ms |
8632 KB |
Output is correct |
30 |
Correct |
57 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
119 ms |
13800 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
121 ms |
9424 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
51 ms |
5696 KB |
Output is correct |
22 |
Correct |
15 ms |
1300 KB |
Output is correct |
23 |
Correct |
9 ms |
1132 KB |
Output is correct |
24 |
Correct |
69 ms |
5840 KB |
Output is correct |
25 |
Correct |
34 ms |
3272 KB |
Output is correct |
26 |
Correct |
54 ms |
3532 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
35 ms |
3248 KB |
Output is correct |
29 |
Correct |
28 ms |
5300 KB |
Output is correct |
30 |
Correct |
61 ms |
5968 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
328 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
130 ms |
8632 KB |
Output is correct |
42 |
Correct |
34 ms |
2004 KB |
Output is correct |
43 |
Correct |
15 ms |
1876 KB |
Output is correct |
44 |
Correct |
56 ms |
5896 KB |
Output is correct |
45 |
Correct |
136 ms |
8508 KB |
Output is correct |
46 |
Correct |
43 ms |
5708 KB |
Output is correct |
47 |
Correct |
18 ms |
2000 KB |
Output is correct |
48 |
Correct |
193 ms |
8672 KB |
Output is correct |
49 |
Correct |
136 ms |
8632 KB |
Output is correct |
50 |
Correct |
57 ms |
3448 KB |
Output is correct |
51 |
Correct |
17 ms |
2144 KB |
Output is correct |
52 |
Correct |
124 ms |
9272 KB |
Output is correct |
53 |
Correct |
130 ms |
9240 KB |
Output is correct |
54 |
Correct |
37 ms |
3812 KB |
Output is correct |
55 |
Correct |
80 ms |
6908 KB |
Output is correct |
56 |
Correct |
71 ms |
6208 KB |
Output is correct |
57 |
Correct |
54 ms |
6580 KB |
Output is correct |
58 |
Correct |
140 ms |
9196 KB |
Output is correct |
59 |
Correct |
57 ms |
3544 KB |
Output is correct |
60 |
Correct |
50 ms |
4680 KB |
Output is correct |