#include <iostream>
#include <algorithm>
#include <vector>
#define pii pair<int,int>
#define fst first
#define snd second
using namespace std;
int k,n,x,dt[500001]={};
vector<pii> v;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>k>>n;
for (int i=0;i<n;i++)
{
int l = 0,r = k;
cin>>x;
for (int j=0;j<x;j++)
{
cin>>dt[j];l+=dt[j];
}
l-=dt[x-1];
for (int j=x-1;j>=0;j--)
{
int l1 = l,r1 = l+dt[j],r2 = r,l2 = r-dt[j];
//cout<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<"\n";
if (max(l1,l2)<min(r1,r2))
{
v.push_back({max(l1,l2),min(r1,r2)});
}
if (j) {l-=dt[j-1];}
r-=dt[j];
}
}
sort(v.begin(),v.end());
int rs = 0,l = -1,r = -1;
for (int i=0;i<v.size();i++)
{
if (r<v[i].fst) {rs += r-l;l = v[i].fst;r = v[i].fst;}
r = max(r,v[i].snd);
}
rs += r-l;
cout<<rs<<"\n";
return 0;
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
113 ms |
10264 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
115 ms |
7908 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
3816 KB |
Output is correct |
2 |
Correct |
8 ms |
1136 KB |
Output is correct |
3 |
Correct |
8 ms |
1004 KB |
Output is correct |
4 |
Correct |
33 ms |
3944 KB |
Output is correct |
5 |
Correct |
15 ms |
2432 KB |
Output is correct |
6 |
Correct |
30 ms |
3184 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
36 ms |
2924 KB |
Output is correct |
9 |
Correct |
22 ms |
3304 KB |
Output is correct |
10 |
Correct |
40 ms |
4072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
3816 KB |
Output is correct |
2 |
Correct |
8 ms |
1136 KB |
Output is correct |
3 |
Correct |
8 ms |
1004 KB |
Output is correct |
4 |
Correct |
33 ms |
3944 KB |
Output is correct |
5 |
Correct |
15 ms |
2432 KB |
Output is correct |
6 |
Correct |
30 ms |
3184 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
36 ms |
2924 KB |
Output is correct |
9 |
Correct |
22 ms |
3304 KB |
Output is correct |
10 |
Correct |
40 ms |
4072 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
137 ms |
6756 KB |
Output is correct |
22 |
Correct |
18 ms |
1644 KB |
Output is correct |
23 |
Correct |
14 ms |
1392 KB |
Output is correct |
24 |
Correct |
60 ms |
3944 KB |
Output is correct |
25 |
Correct |
115 ms |
6788 KB |
Output is correct |
26 |
Correct |
49 ms |
3816 KB |
Output is correct |
27 |
Correct |
16 ms |
1520 KB |
Output is correct |
28 |
Correct |
126 ms |
6756 KB |
Output is correct |
29 |
Correct |
109 ms |
6756 KB |
Output is correct |
30 |
Correct |
42 ms |
2664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
113 ms |
10264 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
115 ms |
7908 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
36 ms |
3816 KB |
Output is correct |
22 |
Correct |
8 ms |
1136 KB |
Output is correct |
23 |
Correct |
8 ms |
1004 KB |
Output is correct |
24 |
Correct |
33 ms |
3944 KB |
Output is correct |
25 |
Correct |
15 ms |
2432 KB |
Output is correct |
26 |
Correct |
30 ms |
3184 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
36 ms |
2924 KB |
Output is correct |
29 |
Correct |
22 ms |
3304 KB |
Output is correct |
30 |
Correct |
40 ms |
4072 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
137 ms |
6756 KB |
Output is correct |
42 |
Correct |
18 ms |
1644 KB |
Output is correct |
43 |
Correct |
14 ms |
1392 KB |
Output is correct |
44 |
Correct |
60 ms |
3944 KB |
Output is correct |
45 |
Correct |
115 ms |
6788 KB |
Output is correct |
46 |
Correct |
49 ms |
3816 KB |
Output is correct |
47 |
Correct |
16 ms |
1520 KB |
Output is correct |
48 |
Correct |
126 ms |
6756 KB |
Output is correct |
49 |
Correct |
109 ms |
6756 KB |
Output is correct |
50 |
Correct |
42 ms |
2664 KB |
Output is correct |
51 |
Correct |
16 ms |
1772 KB |
Output is correct |
52 |
Correct |
118 ms |
7972 KB |
Output is correct |
53 |
Correct |
125 ms |
7804 KB |
Output is correct |
54 |
Correct |
30 ms |
3064 KB |
Output is correct |
55 |
Correct |
69 ms |
5400 KB |
Output is correct |
56 |
Correct |
48 ms |
4240 KB |
Output is correct |
57 |
Correct |
55 ms |
4584 KB |
Output is correct |
58 |
Correct |
124 ms |
8036 KB |
Output is correct |
59 |
Correct |
36 ms |
2792 KB |
Output is correct |
60 |
Correct |
48 ms |
3816 KB |
Output is correct |