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;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int l, r; cin >> l >> r;
vector<pair<int, int>>seg;
for(int i = 1; i <= r; i++){
int left = 0, right = l;
int x; cin >> x;
vector<int>v(x);
for(int j = 0; j < x; j++){
cin >> v[j];
left += v[j];
}
left -= v.back();
for(int j = x - 1; j >= 0; j--){
int l1 = left, r1 = left + v[j];
int l2 = right - v[j], r2 = right;
if(max(l1, l2) < min(r1, r2)){
seg.emplace_back(max(l1, l2), min(r1, r2));
}
if(j) left -= v[j - 1];
right -= v[j];
}
}
sort(seg.begin(), seg.end());
int ans = 0;
int left = 0, right = 0;
int sz = seg.size();
while(left < sz && right < sz){
while(right + 1 < sz && seg[right + 1].first <= seg[right].second) right++;
ans += (seg[right].second - seg[left].first);
left = right + 1;
right = left;
}
cout << ans << '\n';
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... |