forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0044.cpp
More file actions
36 lines (32 loc) · 692 Bytes
/
B0044.cpp
File metadata and controls
36 lines (32 loc) · 692 Bytes
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
// Problem Code: COPS
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int copsAndThief(int x, int y, vector<int> M) {
vector<bool> houses(101);
int lower, upper, prod = x*y;
houses[0] = true;
for(int i=0 ; i<M.size() ; i++) {
lower = max(1, M[i] - prod);
upper = min(100, M[i] + prod);
for(int j=lower ; j<=upper ; j++)
houses[j] = true;
}
return count(houses.begin(), houses.end(), false);
}
int main() {
int T, M, x, y, num;
vector<int> cops;
cin >> T;
while(T--) {
cin >> M >> x >> y;
for(int i=0 ; i<M ; i++) {
cin >> num;
cops.push_back(num);
}
cout << copsAndThief(x, y, cops) << endl;
cops.clear();
}
return 0;
}