# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477237 | niloyroot | Lasers (NOI19_lasers) | C++14 | 187 ms | 45032 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>
using namespace std;
#define forp(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define newl '\n'
void solve(){
ll l,r; cin>>l>>r;
vector<ll> R[r+1];
ll x,u,s;
ll sum[r+1];
forp(i,1,r){
cin>>x; s=0;
forp(j,1,x){
cin>>u;
s+=u;
R[i].push_back(u);
}
sum[i]=s;
}
ll s1,s2;
vector<pair<ll,ll>> v;
forp(i,1,r){
s1=0; s2=sum[i];
for(auto e:R[i]){
s2-=e;
if(l-s1-s2<2*e){
v.push_back({l-(s2+e)+1,s1+e});
}
s1+=e;
}
}
sort(v.begin(), v.end());
v.push_back({-1,-1});
ll mx=0,ans=0;
forp(i,0,v.size()-1){
if(v[i].first!=v[i+1].first){
if(v[i].first>mx){
ans+=v[i].second-v[i].first+1;
mx=v[i].second;
} else if(v[i].second>mx){
ans+=(v[i].second-mx);
mx=v[i].second;
}
}
}
cout<<ans<<newl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
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... |