This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define longlonginf LONG_LONG_MAX
using namespace std;
ll n,m,x;
ll l,r;
void solve(){
cin>>n;
cin>>m;
vector<vector<ll>> v(m+5);
ll rem[m+5];
memset(rem,0,sizeof(rem));
for(int i = 0 ; i < m ; i++){
cin>>x;
while(x--){
ll k;
cin>>k;
v[i].push_back(k);
rem[i] += k;
}
rem[i] = n-rem[i];
}
vector<pair<ll,ll>> p;
for(int i = 0 ; i < m ; i++){
ll k = 0;
for(auto x : v[i]){
r = k+x;
l = k+1;
if( l+rem[i]-1 < r ){
p.push_back({l+rem[i],r});
//cout<<"{"<<l+rem[i]<<","<<r<<"} ";
}
k += x;
}
//cout<<"\n";
}
if( p.empty() ){
cout<<0<<"\n";
return;
}
sort(p.begin(),p.end());
p.push_back({longlonginf,longlonginf});
ll cur = p[0].first;
ll mx = p[0].second;
ll ans = 0;
for(auto x : p){
if( x.first <= mx ){
mx = max(mx,x.second);
}
else{
//cout<<"! "<<cur<<" "<<mx<<"\n";
ans += mx-cur+1;
cur = x.first;
mx = max(mx,x.second);
}
}
cout<<ans<<"\n";
}
int main(){
int T = 1;
//cin>>T;
for(int i = 1 ; i <= T ; i++){
solve();
}
return 0;
}
# | 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... |