# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007974 | Luvidi | Lasers (NOI19_lasers) | C++17 | 94 ms | 32972 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 ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int l,r;
cin>>l>>r;
vector<int> a[r];
for (int i=0;i<r;i++){
int x;
cin>>x;
while(x--){
int y;
cin>>y;
a[i].pb(y);
}
}
vector<pii> seg;
for (int i=0;i<r;i++){
int s=a[i].size();
int pre[s],suf[s];
pre[0]=a[i][0];
for (int j=1;j<s;j++)pre[j]=pre[j-1]+a[i][j];
suf[s-1]=a[i][s-1];
for (int j=s-2;j>=0;j--)suf[j]=suf[j+1]+a[i][j];
for (int j=0;j<s;j++){
int le=l-suf[j]+1, ri=pre[j];
if(le<=ri)seg.pb({le,ri});
}
}
sort(seg.begin(),seg.end());
int ans=0,le=0,ri=-1;
for (int i=0;i<seg.size();i++){
if(seg[i].fs>ri){
ans+=ri-le+1;
le=seg[i].fs;
}
ri=max(ri,seg[i].sc);
}
cout<<ans+ri-le+1;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
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... |