#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll l, r;
std::cin >> l >> r;
std::vector<bool> good(r);
ll good_sum = 0;
std::priority_queue<std::pair<ll, ll>, std::vector<std::pair<ll, ll>>,
std::greater<>>
pq;
std::vector<ll> left(r), sum(r);
std::vector<std::deque<ll>> rows(r);
for (ll cnt = 0; cnt < r; ++cnt) {
auto &v = rows[cnt];
ll len;
std::cin >> len;
v.resize(len);
for (auto &i : v) {
std::cin >> i;
}
sum[cnt] = std::accumulate(v.begin(), v.end(), 0LL);
pq.push({left[cnt] + v[0], cnt});
v.pop_front();
if (1 < l - (sum[cnt] - left[cnt]) + 1) {
good[cnt] = true;
good_sum++;
} else {
good[cnt] = false;
}
}
ll ans = 0;
for (ll i = 1; i <= l; ++i) {
while (!pq.empty() and pq.top().first < i) {
auto [l, i] = pq.top();
pq.pop();
left[i] = l;
// x blocks from right ==> l - x + 1 from left
good_sum -= good[i];
if (i < l - (sum[i] - left[i]) + 1) {
good[i] = true;
good_sum++;
} else {
good[i] = false;
}
if (!rows[i].empty()) {
pq.push({left[i] + rows[i][0], i});
rows[i].pop_front();
}
}
ans += good_sum != r;
}
std::cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
828 ms |
348 KB |
Output is correct |
2 |
Correct |
417 ms |
344 KB |
Output is correct |
3 |
Incorrect |
810 ms |
432 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
828 ms |
348 KB |
Output is correct |
2 |
Correct |
417 ms |
344 KB |
Output is correct |
3 |
Incorrect |
810 ms |
432 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
3420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
3420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
828 ms |
348 KB |
Output is correct |
2 |
Correct |
417 ms |
344 KB |
Output is correct |
3 |
Incorrect |
810 ms |
432 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |