#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
vector<pii> order;
int n,m,l,ans;
int main(){
cin>>l>>n;
for (int i=0;i<n;i++){
vector<int> nw;int rtot=0,ltot=0;
cin>>m;nw.resize(m);
for (int j=0;j<m;j++){
cin>>nw[j];rtot+=nw[j];
}
for (int j=0;j<m;j++){
rtot-=nw[j];
if (l-rtot-ltot<2*nw[j]){
order.push_back({l-rtot-nw[j]+1,ltot+nw[j]});
}
ltot+=nw[j];
}
}
sort(order.begin(),order.end());
if (order.size()==0){
cout<<0;
return 0;
}
int prv=order[0].second,sub=order[0].second-order[0].first;
for (pii i :order){
if (i.second<=prv){
continue;
}
if (i.first>prv){
ans+=sub+1;
sub = i.second-i.first;
prv=i.second;
}
else{
sub+=i.second-prv;
prv=i.second;
}
}
cout<<ans+sub+1;
}
# | 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... |