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::sync_with_stdio(0); cin.tie(0);
map<int, int> pref;
int l, r; cin >> l >> r;
for (int i = 0; i < r; i++) {
int x; cin >> x;
vector<int> vals(x);
int sum = 0, pos = 0;
for (int j = 0; j < x; j++) {
cin >> vals[j];
sum += vals[j];
}
for (int j = 0; j < x; j++) {
int len = l - sum - pos + vals[j];
if (vals[j] - (len - vals[j]) > 0) {
pref[l - sum]++;
pref[l - sum + vals[j] - (len - vals[j])]--;
}
sum -= vals[j];
pos += vals[j];
}
}
int cnt = 0, start = 0, ans = 0;
for (auto i : pref) {
bool no = cnt == 0;
cnt += i.second;
if (i.second > 0) {
if (no) {
start = i.first;
}
} else {
if (cnt == 0) {
ans += i.first - start;
// cerr << start << ' ' << i.first - 1 << '\n';
}
}
}
cout << ans;
}
# | 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... |