// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define eb emplace_back // faster than push_back xD
// pbds UwU
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> // use pair for ms
// my io library :D
#define m1(x) template<class T, class... U> void x(T&& a, U&&... b)
#define m2(x) (ll[]){(x forward<U>(b),0)...}
m1(pr){cout << forward<T>(a); m2(cout << " " <<); cout << "\n";}
m1(re){cin >> forward<T>(a); m2(cin >>);}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll l, r;
re(l, r);
vector<vector<ll>> x(r);
for (ll i = 0; i < r; i++) {
ll X;
re(X);
for (ll j = 0; j < X; j++) {
ll c;
re(c);
x[i].push_back(c);
}
}
ll w1 = accumulate(x[0].begin(), x[0].end(), 0LL);
ll w2 = accumulate(x[1].begin(), x[1].end(), 0LL);
ll l1 = max(1LL, l - w1 + 1), r1 = min(l, w1);
ll l2 = max(1LL, l - w2 + 1), r2 = min(l, w2);
ll len1 = max(0LL, r1 - l1 + 1);
ll len2 = max(0LL, r2 - l2 + 1);
ll ans;
if (r1 < l2 || r2 < l1) {
ans = len1 + len2;
} else {
ll L = min(l1, l2);
ll R = max(r1, r2);
ans = max(0LL, R - L + 1);
}
pr(ans);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |