#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int l, r, curr[N], sum[N];
vector<int> s[2 * N], pt;
multiset<int> S;
map<int, vector<int>> M;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> l >> r;
int ans = 0;
for(int i = 0; i < r; i++) {
int x; cin >> x;
for(int j = 0; j < x; j++) {
int p; cin >> p;
sum[i] += p;
M[sum[i]].push_back(i);
pt.push_back(sum[i]);
}
S.insert(sum[i]);
}
sort(pt.begin(), pt.end());
pt.erase(unique(pt.begin(), pt.end()), pt.end());
int last = 0;
for(auto [x, v] : M) {
if(l - x < *S.rbegin()) ans += x - last;
for(auto j : v) {
S.erase(S.find(sum[j] - curr[j]));
curr[j] = x;
S.insert(sum[j] - curr[j]);
}
last = x;
}
if(0 < *S.rbegin()) ans += l - last;
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23720 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23720 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
55320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
23764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
156 ms |
55320 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Incorrect |
12 ms |
23720 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |