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<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l,r;
cin>>l>>r;
vector<pi>cv;
for(int i=0;i<r;i++)
{
int x;
cin>>x;
vector<int>v(x);
for(int&t:v)
cin>>t;
int sm=0,csm=0;
for(int&t:v)
sm+=t;
for(int&t:v)
{
if(l-sm<t)
cv.eb(l-sm+csm,1),cv.eb(csm+t,-1);
csm+=t;
}
}
sort(all(cv));
int cur=0,csm=0;
int ans=0;
for(pi&t:cv)
{
if(csm>0)
ans+=t.fi-cur;
cur=t.fi;
csm+=t.se;
}
cout<<ans<<endl;
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... |