#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int l, r, curr[N], sum[N];
multiset<int> S;
map<int, vector<int>> M;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> l >> r;
int ans = 0;
for(int i = 0; i < r; i++) {
int x; cin >> x;
for(int j = 0; j < x; j++) {
int p; cin >> p;
sum[i] += p;
M[sum[i]].push_back(i);
}
S.insert(sum[i]);
}
int last = 0;
for(auto [x, v] : M) {
if(l - x < *S.rbegin()) {
ans += x - max(last, (l - *S.rbegin()));
}
for(auto j : v) {
S.erase(S.find(sum[j] - curr[j]));
curr[j] = x;
S.insert(sum[j] - curr[j]);
}
last = x;
}
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
375 ms |
36768 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
902 ms |
87924 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
30660 KB |
Output is correct |
2 |
Correct |
27 ms |
7740 KB |
Output is correct |
3 |
Correct |
34 ms |
9892 KB |
Output is correct |
4 |
Correct |
120 ms |
30776 KB |
Output is correct |
5 |
Correct |
50 ms |
15684 KB |
Output is correct |
6 |
Correct |
163 ms |
41396 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
175 ms |
44456 KB |
Output is correct |
9 |
Correct |
62 ms |
17112 KB |
Output is correct |
10 |
Correct |
124 ms |
33972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 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 |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
30660 KB |
Output is correct |
2 |
Correct |
27 ms |
7740 KB |
Output is correct |
3 |
Correct |
34 ms |
9892 KB |
Output is correct |
4 |
Correct |
120 ms |
30776 KB |
Output is correct |
5 |
Correct |
50 ms |
15684 KB |
Output is correct |
6 |
Correct |
163 ms |
41396 KB |
Output is correct |
7 |
Correct |
2 ms |
852 KB |
Output is correct |
8 |
Correct |
175 ms |
44456 KB |
Output is correct |
9 |
Correct |
62 ms |
17112 KB |
Output is correct |
10 |
Correct |
124 ms |
33972 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
324 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 |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
961 ms |
69012 KB |
Output is correct |
22 |
Correct |
108 ms |
13268 KB |
Output is correct |
23 |
Correct |
39 ms |
10244 KB |
Output is correct |
24 |
Correct |
215 ms |
40304 KB |
Output is correct |
25 |
Correct |
939 ms |
68860 KB |
Output is correct |
26 |
Correct |
255 ms |
25632 KB |
Output is correct |
27 |
Correct |
105 ms |
11304 KB |
Output is correct |
28 |
Correct |
942 ms |
68600 KB |
Output is correct |
29 |
Correct |
944 ms |
69188 KB |
Output is correct |
30 |
Correct |
153 ms |
32448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
375 ms |
36768 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
902 ms |
87924 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
118 ms |
30660 KB |
Output is correct |
22 |
Correct |
27 ms |
7740 KB |
Output is correct |
23 |
Correct |
34 ms |
9892 KB |
Output is correct |
24 |
Correct |
120 ms |
30776 KB |
Output is correct |
25 |
Correct |
50 ms |
15684 KB |
Output is correct |
26 |
Correct |
163 ms |
41396 KB |
Output is correct |
27 |
Correct |
2 ms |
852 KB |
Output is correct |
28 |
Correct |
175 ms |
44456 KB |
Output is correct |
29 |
Correct |
62 ms |
17112 KB |
Output is correct |
30 |
Correct |
124 ms |
33972 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
324 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 |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
961 ms |
69012 KB |
Output is correct |
42 |
Correct |
108 ms |
13268 KB |
Output is correct |
43 |
Correct |
39 ms |
10244 KB |
Output is correct |
44 |
Correct |
215 ms |
40304 KB |
Output is correct |
45 |
Correct |
939 ms |
68860 KB |
Output is correct |
46 |
Correct |
255 ms |
25632 KB |
Output is correct |
47 |
Correct |
105 ms |
11304 KB |
Output is correct |
48 |
Correct |
942 ms |
68600 KB |
Output is correct |
49 |
Correct |
944 ms |
69188 KB |
Output is correct |
50 |
Correct |
153 ms |
32448 KB |
Output is correct |
51 |
Correct |
58 ms |
14112 KB |
Output is correct |
52 |
Correct |
905 ms |
86776 KB |
Output is correct |
53 |
Correct |
894 ms |
86984 KB |
Output is correct |
54 |
Correct |
181 ms |
22248 KB |
Output is correct |
55 |
Correct |
513 ms |
53508 KB |
Output is correct |
56 |
Correct |
169 ms |
37040 KB |
Output is correct |
57 |
Correct |
302 ms |
34612 KB |
Output is correct |
58 |
Correct |
921 ms |
87476 KB |
Output is correct |
59 |
Correct |
222 ms |
25596 KB |
Output is correct |
60 |
Correct |
326 ms |
36476 KB |
Output is correct |