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>
using namespace std;
using pi = pair<int,int>;
int l,r,in,n,ans=0;
int qs[50002]={};
vector<pi> ep;
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin >> l >> r;
qs[0]=0;
for(int i=0;i<r;i++){
cin >> n;
for(int j=1;j<=n;j++){
cin >> qs[j];
qs[j]+=qs[j-1];
}
//qs[n+1]=qs[n];
for(int j=1;j<=n;j++){
//gen ep
int sp=qs[j-1],sn=qs[n]-qs[j],val=qs[j]-qs[j-1];
int L=val,M=l-sn-sp;
//cout << '=' << L << ' ' << M << endl;
if(M-L+1 > L)continue;
ep.push_back({M-L+1+sp,1});
ep.push_back({L+1+sp,-1});
}
}
sort(ep.begin(),ep.end());
ep.push_back({l,-9999});
int block=0;
for(int i=0,j=ep.size()-1;i<j;i++){
auto[indx,v]=ep[i];
//cout << indx << ' ' << v << ' ' << endl;
block+=v;
if(block>=1 && (ep[i+1]).first > indx){
ans+=((ep[i+1]).first - indx);
}
}
cout << ans;
return 0;
}
/*
11 3
2 2 3
1 7
2 4 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... |