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>> blocks;
for(int i = 0;i<R;++i){
int X; cin >> X;
vector<int> W(X+1);
int l = 0, r = L;
for(int j = 1;j<=X;++j){
cin >> W[j];
l += W[j];
}
l -= W[X];
for(int j = X;j>=1;--j){
int l1 = l, l2 = r-W[j], r1 = r, r2 = l+W[j];
if(max(l1,l2) < min(r1,r2)){
blocks.push_back({max(l1,l2),min(r1,r2)});
}
if(j != 1) l -= W[j-1];
r -= W[j];
}
}
sort(blocks.begin(),blocks.end());
int l = 0, r = 0, ans = 0;
for(int i = 0;i<blocks.size();++i){
if(blocks[i].first > r){
ans += r-l;
l = r = blocks[i].first;
}
r = max(r,blocks[i].second);
}
ans += r-l;
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
lasers.cpp: In function 'int main()':
lasers.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for(int i = 0;i<blocks.size();++i){
| ~^~~~~~~~~~~~~~
# | 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... |