# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
643011 | devariaota | Lasers (NOI19_lasers) | C++17 | 270 ms | 13284 KiB |
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 fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MOD=1e9+7;
using namespace std;
ll N,M,s[500005];
vector <pair<ll,ll> > vec;
int main(){
cin>>N>>M;
for(int i=1;i<=M;i++){
cin>>s[i];
ll a[s[i]+1];
ll pref[s[i]+1];
ll suff[s[i]+1];
for(int j=1;j<=s[i];j++){
ll y;
cin>>y;
a[j]=y;
}
pref[0]=0;
suff[s[i]+1]=0;
for(int j=1;j<=s[i];j++){
pref[j]=pref[j-1]+a[j];
}
for(int j=s[i];j>=1;j--){
suff[j]=suff[j+1]+a[j];
}
for(int j=1;j<=s[i];j++){
ll l=N-suff[j]+1;
ll r=pref[j];
if(l<=r){
vec.push_back({l,r});
}
}
}
sort(vec.begin(),vec.end());
if(vec.empty()){
cout<<0<<endl;
return 0;
}
ll l=vec[0].fi;
ll r=vec[0].se;
ll ans=r-l+1;
for(int i=1;i<vec.size();i++){
if(vec[i].fi>r){
l=vec[i].fi;
r=vec[i].se;
ans+=vec[i].se-vec[i].fi+1;
}
else if(vec[i].se>r){
l=vec[i].fi;
r=vec[i].se;
ans+=vec[i].se-r;
}
}
cout<<ans<<endl;
}
/*
20 6
1 8
2 2 8
3 2 2 8
4 2 2 2 8
5 2 2 2 2 8
6 2 2 2 2 2 8
*/
Compilation message (stderr)
# | 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... |