#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define piii pair<pair<int,int>,pair<int,int>>
#define pip pair<int,pair<int,int>>
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int ans = 0;
int n, q; cin >> n >> q;
vector<pair<int,int>>v;
for(int i = 1; i <= q; i++){
int x; cin >> x;
int a[x+5];
int tmp = 0;
for(int i = 1; i <= x; i++){
cin >> a[i]; tmp += a[i];
}
int rem = n - tmp;
int cnt = 0;
int last = 0;
for(int i = 1; i <= x; i++){
last += a[i];
int val = a[i] - rem;
if(val <= 0)continue;
v.pb({last-val+1,last});
}
}
sort(v.begin(),v.end());
int last = 0;
for(int i = 0; i < v.size(); i++){
//cout << "here >> " << v[i].fi << " " << v[i].se << endl;
if(v[i].fi > last){
ans += (v[i].se - v[i].fi + 1);
last = v[i].se;
}
else if(v[i].se > last){
ans += (v[i].se - last);
last = v[i].se;
}
}
cout << ans << endl;
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:27:13: warning: unused variable 'cnt' [-Wunused-variable]
27 | int cnt = 0;
| ^~~
lasers.cpp:38:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
61 ms |
12160 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
69 ms |
7216 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
6516 KB |
Output is correct |
2 |
Correct |
5 ms |
1760 KB |
Output is correct |
3 |
Correct |
5 ms |
1480 KB |
Output is correct |
4 |
Correct |
27 ms |
7940 KB |
Output is correct |
5 |
Correct |
11 ms |
3800 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
20 ms |
4428 KB |
Output is correct |
9 |
Correct |
14 ms |
6868 KB |
Output is correct |
10 |
Correct |
28 ms |
7892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
456 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
6516 KB |
Output is correct |
2 |
Correct |
5 ms |
1760 KB |
Output is correct |
3 |
Correct |
5 ms |
1480 KB |
Output is correct |
4 |
Correct |
27 ms |
7940 KB |
Output is correct |
5 |
Correct |
11 ms |
3800 KB |
Output is correct |
6 |
Correct |
18 ms |
4996 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
20 ms |
4428 KB |
Output is correct |
9 |
Correct |
14 ms |
6868 KB |
Output is correct |
10 |
Correct |
28 ms |
7892 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
452 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
66 ms |
8640 KB |
Output is correct |
22 |
Correct |
11 ms |
2048 KB |
Output is correct |
23 |
Correct |
7 ms |
2012 KB |
Output is correct |
24 |
Correct |
27 ms |
6832 KB |
Output is correct |
25 |
Correct |
65 ms |
8636 KB |
Output is correct |
26 |
Correct |
23 ms |
6608 KB |
Output is correct |
27 |
Correct |
9 ms |
2008 KB |
Output is correct |
28 |
Correct |
64 ms |
8508 KB |
Output is correct |
29 |
Correct |
65 ms |
8640 KB |
Output is correct |
30 |
Correct |
20 ms |
3796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
61 ms |
12160 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
69 ms |
7216 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
26 ms |
6516 KB |
Output is correct |
22 |
Correct |
5 ms |
1760 KB |
Output is correct |
23 |
Correct |
5 ms |
1480 KB |
Output is correct |
24 |
Correct |
27 ms |
7940 KB |
Output is correct |
25 |
Correct |
11 ms |
3800 KB |
Output is correct |
26 |
Correct |
18 ms |
4996 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
20 ms |
4428 KB |
Output is correct |
29 |
Correct |
14 ms |
6868 KB |
Output is correct |
30 |
Correct |
28 ms |
7892 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
452 KB |
Output is correct |
33 |
Correct |
0 ms |
452 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
456 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
66 ms |
8640 KB |
Output is correct |
42 |
Correct |
11 ms |
2048 KB |
Output is correct |
43 |
Correct |
7 ms |
2012 KB |
Output is correct |
44 |
Correct |
27 ms |
6832 KB |
Output is correct |
45 |
Correct |
65 ms |
8636 KB |
Output is correct |
46 |
Correct |
23 ms |
6608 KB |
Output is correct |
47 |
Correct |
9 ms |
2008 KB |
Output is correct |
48 |
Correct |
64 ms |
8508 KB |
Output is correct |
49 |
Correct |
65 ms |
8640 KB |
Output is correct |
50 |
Correct |
20 ms |
3796 KB |
Output is correct |
51 |
Correct |
10 ms |
2268 KB |
Output is correct |
52 |
Correct |
68 ms |
9888 KB |
Output is correct |
53 |
Correct |
67 ms |
9664 KB |
Output is correct |
54 |
Correct |
17 ms |
4052 KB |
Output is correct |
55 |
Correct |
40 ms |
8916 KB |
Output is correct |
56 |
Correct |
24 ms |
8660 KB |
Output is correct |
57 |
Correct |
27 ms |
6840 KB |
Output is correct |
58 |
Correct |
69 ms |
9988 KB |
Output is correct |
59 |
Correct |
20 ms |
3540 KB |
Output is correct |
60 |
Correct |
28 ms |
5068 KB |
Output is correct |