-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsnowboots.cpp
64 lines (62 loc) · 1.62 KB
/
snowboots.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <fstream>
#include <array>
#include <vector>
#include <utility>
using namespace std;
int main(){
ifstream fin("snowboots.in");
ofstream fout("snowboots.out");
int N, B;
array<int, 250> sDepth;
array<pair<int, int>, 250> boots;
array<array<int, 250>, 250> bkSteps;
fin >> N >> B;
for(int i = 0; i < N; i++)
fin >> sDepth[i];
for(int i = 0; i < B; i++)
fin >> get<0>(boots[i]) >> get<1>(boots[i]);
for(int i = 0; i < B; i++){
int mDepth = get<0>(boots[i]);
int mStep = get<1>(boots[i]);
int prevStep = N-1;
for(int j = N-1; j >= 0; j--){
if(sDepth[j] > mDepth){
bkSteps[i][j] = -1; // Unable to step
continue;
}
if(prevStep - j <= mStep)
bkSteps[i][prevStep] = j;
else
bkSteps[i][prevStep] = -1; // New step cycle
prevStep = j;
}
}
int cPos = 0;
int bootN = 0;
int ret = 0;
while(cPos < N-1){
int begPos = N-1;
bool finding = false;
for(int i = N-1; i >= cPos || sDepth[i] > get<0>(boots[bootN]);){
if(bkSteps[bootN][i] == -1){
i--;
finding = true;
begPos = cPos;
continue;
}
if(finding){
finding = false;
begPos = i;
}
i = bkSteps[bootN][i];
if(i == 0)
break;
}
cPos = begPos;
bootN++;
ret++;
}
fout << ret - 1 << endl;
return 0;
}