#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define bg begin
#define ed end
#define ft front
#define bk back
#define sz(x) (int)(x).size()
#define all(x) (x).bg(), (x).ed()
#define mtp make_tuple
#define ins insert
#define ers erase
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define str string
#define pi pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { WHILE(b) { a %= b; swap(a, b); } return b; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
int l, r;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> l >> r;
vpi s;
FRN(i, r) {
int x;
cin >> x;
vi a(x, 0);
int sum1 = 0, sum2 = 0;
FRN(j, x) {
cin >> a[j];
sum2 += a[j];
}
FRN(j, x) {
if (sum1 + a[j] + sum2 > l) s.pb({l - sum2 + 1, sum1 + a[j]});
sum1 += a[j];
sum2 -= a[j];
}
}
if (s.empty()) {
cout << 0;
return 0;
}
sort(all(s));
int ln = s[0].st, rn = s[0].nd, rs = 0;
FRN(i, sz(s))
if (s[i].st > rn) {
rs += rn - ln + 1;
ln = s[i].st;
rn = s[i].nd;
}
else rn = max(rn, s[i].nd);
rs += rn - ln + 1;
cout << rs;
return 0;
}
/*
11 3
2 2 3
1 7
2 4 1
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 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 |
324 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 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 |
324 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
103 ms |
10188 KB |
Output is correct |
13 |
Correct |
0 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
360 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
101 ms |
7852 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3504 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
904 KB |
Output is correct |
4 |
Correct |
33 ms |
3792 KB |
Output is correct |
5 |
Correct |
14 ms |
2380 KB |
Output is correct |
6 |
Correct |
25 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
32 ms |
2872 KB |
Output is correct |
9 |
Correct |
16 ms |
2892 KB |
Output is correct |
10 |
Correct |
32 ms |
3900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
212 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3504 KB |
Output is correct |
2 |
Correct |
6 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
904 KB |
Output is correct |
4 |
Correct |
33 ms |
3792 KB |
Output is correct |
5 |
Correct |
14 ms |
2380 KB |
Output is correct |
6 |
Correct |
25 ms |
2516 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
32 ms |
2872 KB |
Output is correct |
9 |
Correct |
16 ms |
2892 KB |
Output is correct |
10 |
Correct |
32 ms |
3900 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 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 |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
212 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 |
97 ms |
6676 KB |
Output is correct |
22 |
Correct |
14 ms |
1504 KB |
Output is correct |
23 |
Correct |
10 ms |
1224 KB |
Output is correct |
24 |
Correct |
34 ms |
3772 KB |
Output is correct |
25 |
Correct |
110 ms |
6592 KB |
Output is correct |
26 |
Correct |
42 ms |
3668 KB |
Output is correct |
27 |
Correct |
11 ms |
1448 KB |
Output is correct |
28 |
Correct |
96 ms |
6620 KB |
Output is correct |
29 |
Correct |
105 ms |
6692 KB |
Output is correct |
30 |
Correct |
27 ms |
2416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 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 |
324 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
103 ms |
10188 KB |
Output is correct |
13 |
Correct |
0 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
360 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
101 ms |
7852 KB |
Output is correct |
18 |
Correct |
0 ms |
224 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
28 ms |
3504 KB |
Output is correct |
22 |
Correct |
6 ms |
1108 KB |
Output is correct |
23 |
Correct |
6 ms |
904 KB |
Output is correct |
24 |
Correct |
33 ms |
3792 KB |
Output is correct |
25 |
Correct |
14 ms |
2380 KB |
Output is correct |
26 |
Correct |
25 ms |
2516 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
32 ms |
2872 KB |
Output is correct |
29 |
Correct |
16 ms |
2892 KB |
Output is correct |
30 |
Correct |
32 ms |
3900 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 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 |
1 ms |
320 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
212 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 |
97 ms |
6676 KB |
Output is correct |
42 |
Correct |
14 ms |
1504 KB |
Output is correct |
43 |
Correct |
10 ms |
1224 KB |
Output is correct |
44 |
Correct |
34 ms |
3772 KB |
Output is correct |
45 |
Correct |
110 ms |
6592 KB |
Output is correct |
46 |
Correct |
42 ms |
3668 KB |
Output is correct |
47 |
Correct |
11 ms |
1448 KB |
Output is correct |
48 |
Correct |
96 ms |
6620 KB |
Output is correct |
49 |
Correct |
105 ms |
6692 KB |
Output is correct |
50 |
Correct |
27 ms |
2416 KB |
Output is correct |
51 |
Correct |
14 ms |
1612 KB |
Output is correct |
52 |
Correct |
103 ms |
8000 KB |
Output is correct |
53 |
Correct |
103 ms |
7776 KB |
Output is correct |
54 |
Correct |
23 ms |
2852 KB |
Output is correct |
55 |
Correct |
53 ms |
5172 KB |
Output is correct |
56 |
Correct |
34 ms |
4032 KB |
Output is correct |
57 |
Correct |
38 ms |
4560 KB |
Output is correct |
58 |
Correct |
105 ms |
8056 KB |
Output is correct |
59 |
Correct |
27 ms |
2616 KB |
Output is correct |
60 |
Correct |
39 ms |
3668 KB |
Output is correct |