#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define ii pair<int,int>
#define fi first
#define se second
#define vi vector<int>
#define ll long long
#define FORU(i,j,n) for(int i=(j);i<=(n);i++)
#define FORD(i,j,n) for(int i=(j);i>=(n);i--)
using namespace std;
const int N=5e5+5;
int L,n;
int k[N];
vi x[N];
vi l[N],r[N];
set<ii> ans;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>L>>n;
FORU(i,1,n)
{
cin>>k[i];
x[i].resize(k[i]+2,0);
l[i].resize(k[i]+2,0);
r[i].resize(k[i]+2,0);
FORU(j,1,k[i])cin>>x[i][j],l[i][j]=l[i][j-1]+x[i][j];
FORD(j,k[i],1)r[i][j]=r[i][j+1]+x[i][j];
FORU(j,1,k[i])
if(l[i][j-1]+r[i][j]+x[i][j]>L)ans.insert({L-r[i][j]+1,l[i][j]});
}
int res=0,pre=1,cur=0;
for(auto x:ans)
{
if(cur<x.fi-1)
{
res+=cur-pre+1;
pre=x.fi;cur=x.se;
}
else cur=max(cur,x.se);
}
res+=cur-pre+1;
cout<<res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
35540 KB |
Output is correct |
2 |
Correct |
20 ms |
35552 KB |
Output is correct |
3 |
Correct |
23 ms |
35444 KB |
Output is correct |
4 |
Correct |
19 ms |
35560 KB |
Output is correct |
5 |
Correct |
21 ms |
35540 KB |
Output is correct |
6 |
Correct |
18 ms |
35540 KB |
Output is correct |
7 |
Correct |
20 ms |
35556 KB |
Output is correct |
8 |
Correct |
20 ms |
35540 KB |
Output is correct |
9 |
Correct |
19 ms |
35540 KB |
Output is correct |
10 |
Correct |
19 ms |
35464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
35540 KB |
Output is correct |
2 |
Correct |
20 ms |
35552 KB |
Output is correct |
3 |
Correct |
23 ms |
35444 KB |
Output is correct |
4 |
Correct |
19 ms |
35560 KB |
Output is correct |
5 |
Correct |
21 ms |
35540 KB |
Output is correct |
6 |
Correct |
18 ms |
35540 KB |
Output is correct |
7 |
Correct |
20 ms |
35556 KB |
Output is correct |
8 |
Correct |
20 ms |
35540 KB |
Output is correct |
9 |
Correct |
19 ms |
35540 KB |
Output is correct |
10 |
Correct |
19 ms |
35464 KB |
Output is correct |
11 |
Correct |
20 ms |
35668 KB |
Output is correct |
12 |
Correct |
209 ms |
83428 KB |
Output is correct |
13 |
Correct |
22 ms |
35540 KB |
Output is correct |
14 |
Correct |
23 ms |
35484 KB |
Output is correct |
15 |
Correct |
21 ms |
35668 KB |
Output is correct |
16 |
Correct |
20 ms |
35552 KB |
Output is correct |
17 |
Correct |
362 ms |
93956 KB |
Output is correct |
18 |
Correct |
20 ms |
35540 KB |
Output is correct |
19 |
Correct |
20 ms |
35500 KB |
Output is correct |
20 |
Correct |
20 ms |
35524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
47052 KB |
Output is correct |
2 |
Correct |
31 ms |
37624 KB |
Output is correct |
3 |
Correct |
28 ms |
37332 KB |
Output is correct |
4 |
Correct |
70 ms |
47900 KB |
Output is correct |
5 |
Correct |
40 ms |
40276 KB |
Output is correct |
6 |
Correct |
49 ms |
42564 KB |
Output is correct |
7 |
Correct |
21 ms |
35704 KB |
Output is correct |
8 |
Correct |
56 ms |
43816 KB |
Output is correct |
9 |
Correct |
55 ms |
43804 KB |
Output is correct |
10 |
Correct |
82 ms |
49924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
35540 KB |
Output is correct |
2 |
Correct |
21 ms |
35448 KB |
Output is correct |
3 |
Correct |
20 ms |
35452 KB |
Output is correct |
4 |
Correct |
23 ms |
35540 KB |
Output is correct |
5 |
Correct |
21 ms |
35564 KB |
Output is correct |
6 |
Correct |
20 ms |
35540 KB |
Output is correct |
7 |
Correct |
21 ms |
35548 KB |
Output is correct |
8 |
Correct |
21 ms |
35640 KB |
Output is correct |
9 |
Correct |
23 ms |
35668 KB |
Output is correct |
10 |
Correct |
20 ms |
35536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
47052 KB |
Output is correct |
2 |
Correct |
31 ms |
37624 KB |
Output is correct |
3 |
Correct |
28 ms |
37332 KB |
Output is correct |
4 |
Correct |
70 ms |
47900 KB |
Output is correct |
5 |
Correct |
40 ms |
40276 KB |
Output is correct |
6 |
Correct |
49 ms |
42564 KB |
Output is correct |
7 |
Correct |
21 ms |
35704 KB |
Output is correct |
8 |
Correct |
56 ms |
43816 KB |
Output is correct |
9 |
Correct |
55 ms |
43804 KB |
Output is correct |
10 |
Correct |
82 ms |
49924 KB |
Output is correct |
11 |
Correct |
21 ms |
35540 KB |
Output is correct |
12 |
Correct |
21 ms |
35448 KB |
Output is correct |
13 |
Correct |
20 ms |
35452 KB |
Output is correct |
14 |
Correct |
23 ms |
35540 KB |
Output is correct |
15 |
Correct |
21 ms |
35564 KB |
Output is correct |
16 |
Correct |
20 ms |
35540 KB |
Output is correct |
17 |
Correct |
21 ms |
35548 KB |
Output is correct |
18 |
Correct |
21 ms |
35640 KB |
Output is correct |
19 |
Correct |
23 ms |
35668 KB |
Output is correct |
20 |
Correct |
20 ms |
35536 KB |
Output is correct |
21 |
Correct |
386 ms |
92944 KB |
Output is correct |
22 |
Correct |
47 ms |
40040 KB |
Output is correct |
23 |
Correct |
34 ms |
38928 KB |
Output is correct |
24 |
Correct |
81 ms |
49176 KB |
Output is correct |
25 |
Correct |
385 ms |
92868 KB |
Output is correct |
26 |
Correct |
80 ms |
45016 KB |
Output is correct |
27 |
Correct |
42 ms |
39196 KB |
Output is correct |
28 |
Correct |
372 ms |
92760 KB |
Output is correct |
29 |
Correct |
384 ms |
93072 KB |
Output is correct |
30 |
Correct |
62 ms |
45316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
35540 KB |
Output is correct |
2 |
Correct |
20 ms |
35552 KB |
Output is correct |
3 |
Correct |
23 ms |
35444 KB |
Output is correct |
4 |
Correct |
19 ms |
35560 KB |
Output is correct |
5 |
Correct |
21 ms |
35540 KB |
Output is correct |
6 |
Correct |
18 ms |
35540 KB |
Output is correct |
7 |
Correct |
20 ms |
35556 KB |
Output is correct |
8 |
Correct |
20 ms |
35540 KB |
Output is correct |
9 |
Correct |
19 ms |
35540 KB |
Output is correct |
10 |
Correct |
19 ms |
35464 KB |
Output is correct |
11 |
Correct |
20 ms |
35668 KB |
Output is correct |
12 |
Correct |
209 ms |
83428 KB |
Output is correct |
13 |
Correct |
22 ms |
35540 KB |
Output is correct |
14 |
Correct |
23 ms |
35484 KB |
Output is correct |
15 |
Correct |
21 ms |
35668 KB |
Output is correct |
16 |
Correct |
20 ms |
35552 KB |
Output is correct |
17 |
Correct |
362 ms |
93956 KB |
Output is correct |
18 |
Correct |
20 ms |
35540 KB |
Output is correct |
19 |
Correct |
20 ms |
35500 KB |
Output is correct |
20 |
Correct |
20 ms |
35524 KB |
Output is correct |
21 |
Correct |
71 ms |
47052 KB |
Output is correct |
22 |
Correct |
31 ms |
37624 KB |
Output is correct |
23 |
Correct |
28 ms |
37332 KB |
Output is correct |
24 |
Correct |
70 ms |
47900 KB |
Output is correct |
25 |
Correct |
40 ms |
40276 KB |
Output is correct |
26 |
Correct |
49 ms |
42564 KB |
Output is correct |
27 |
Correct |
21 ms |
35704 KB |
Output is correct |
28 |
Correct |
56 ms |
43816 KB |
Output is correct |
29 |
Correct |
55 ms |
43804 KB |
Output is correct |
30 |
Correct |
82 ms |
49924 KB |
Output is correct |
31 |
Correct |
21 ms |
35540 KB |
Output is correct |
32 |
Correct |
21 ms |
35448 KB |
Output is correct |
33 |
Correct |
20 ms |
35452 KB |
Output is correct |
34 |
Correct |
23 ms |
35540 KB |
Output is correct |
35 |
Correct |
21 ms |
35564 KB |
Output is correct |
36 |
Correct |
20 ms |
35540 KB |
Output is correct |
37 |
Correct |
21 ms |
35548 KB |
Output is correct |
38 |
Correct |
21 ms |
35640 KB |
Output is correct |
39 |
Correct |
23 ms |
35668 KB |
Output is correct |
40 |
Correct |
20 ms |
35536 KB |
Output is correct |
41 |
Correct |
386 ms |
92944 KB |
Output is correct |
42 |
Correct |
47 ms |
40040 KB |
Output is correct |
43 |
Correct |
34 ms |
38928 KB |
Output is correct |
44 |
Correct |
81 ms |
49176 KB |
Output is correct |
45 |
Correct |
385 ms |
92868 KB |
Output is correct |
46 |
Correct |
80 ms |
45016 KB |
Output is correct |
47 |
Correct |
42 ms |
39196 KB |
Output is correct |
48 |
Correct |
372 ms |
92760 KB |
Output is correct |
49 |
Correct |
384 ms |
93072 KB |
Output is correct |
50 |
Correct |
62 ms |
45316 KB |
Output is correct |
51 |
Correct |
41 ms |
40020 KB |
Output is correct |
52 |
Correct |
415 ms |
94684 KB |
Output is correct |
53 |
Correct |
394 ms |
94944 KB |
Output is correct |
54 |
Correct |
66 ms |
41472 KB |
Output is correct |
55 |
Correct |
137 ms |
50088 KB |
Output is correct |
56 |
Correct |
77 ms |
46824 KB |
Output is correct |
57 |
Correct |
92 ms |
45788 KB |
Output is correct |
58 |
Correct |
407 ms |
95820 KB |
Output is correct |
59 |
Correct |
70 ms |
43212 KB |
Output is correct |
60 |
Correct |
87 ms |
45272 KB |
Output is correct |