-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
44 lines (38 loc) · 1.28 KB
/
D.cpp
File metadata and controls
44 lines (38 loc) · 1.28 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
#include <iostream>
#include <vector>
using namespace std;
int main() {
int t;
cin >> t; // Read number of test cases
while (t--) {
int n;
cin >> n; // Read number of cities
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i]; // Read deadlines for each city
}
int count = 0; // Count of valid starting cities
for (int start = 0; start < n; ++start) { // Try starting from each city
int currentTime = 1;
bool canWin = true;
int left = start, right = start; // Initially conquer the starting city
while (left >= 0 || right < n) {
if (left >= 0 && a[left] >= currentTime) {
currentTime++;
left--;
} else if (right < n && a[right] >= currentTime) {
currentTime++;
right++;
} else {
canWin = false;
break;
}
}
if (canWin) {
count++; // If it's possible to win, increment the count
}
}
cout << count << endl; // Output the count for the current test case
}
return 0;
}