-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11157.cpp
More file actions
49 lines (43 loc) · 1.05 KB
/
11157.cpp
File metadata and controls
49 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int t, n, d, dist[102];
char type;
bool used[102], small[102];
string in;
int main() {
scanf("%d\n", &t);
for (int tt = 1; tt <= t; tt++) {
memset(used, 0, sizeof(used));
memset(small, 0, sizeof(used));
scanf("%d %d\n", &n, &d);
for (int i = 1; i <= n; i++) {
cin >> in;
sscanf(in.c_str(), "%c-%d", &type, &dist[i]);
small[i] = type == 'S';
}
dist[n+1] = d;
int maxGap = 0, lastDist = 0;
bool tookSmall = false;
for (int i = 1; i <= n + 1; i++) {
if (tookSmall and small[i]) {
tookSmall = false;
} else {
maxGap = max(maxGap, dist[i] - lastDist);
lastDist = dist[i];
tookSmall = small[i];
used[i] = true;
}
}
// Go back
for (int i = n; i >= 0; i--) {
if (small[i] and used[i]) continue;
maxGap = max(lastDist - dist[i], maxGap);
lastDist = dist[i];
}
cout << "Case " << tt << ": " << maxGap << endl;
}
return 0;
}