forked from somiljain7/data-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
42 lines (33 loc) · 863 Bytes
/
main.cpp
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
#include <iostream>
#include <vector>
#include <iostream>
#include <vector>
using namespace std;
int compute_min_refills(int dist, int tank, vector<int> & stops) {
int numRefills=0, currentRefill=0;
int n = stops.size();
while(currentRefill<=n){
int lastRefill=currentRefill;
while(currentRefill<=n&&(stops[currentRefill+1]-stops[lastRefill])<=tank){
currentRefill=currentRefill+1;
}
if(currentRefill==lastRefill)
return -1;
if(currentRefill<=n)
numRefills=numRefills+1;
}
return numRefills;
}
int main() {
int d = 0;
cin >> d;
int m = 0;
cin >> m;
int n = 0;
cin >> n;
vector<int> stops(n);
for (size_t i = 0; i < n; ++i)
cin >> stops.at(i);
cout << compute_min_refills(d, m, stops) << "\n";
return 0;
}