-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNETEASE4.cpp
64 lines (58 loc) · 1.01 KB
/
NETEASE4.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 <vector>
using namespace std;
bool IsReachable(const vector<int>& heights, int k)
{
if ((int)heights.size() - 0 <= k + 1) return true;
bool fly = true;
int size = heights.size();
for (int i = 0; i < size; ) // this loop is ensured to end
{
bool moveable = false;
for (int j = min(i+k, size-1); j >= i+1; --j)
{
if (heights[j] <= heights[i])
{
i = j;
moveable = true;
break;
}
}
if (!moveable)
{
if (fly)
{
i = min(size-1, i+k);
fly = false;
}
else
{
return false;
}
}
if (i == size-1) return true;
}
return false;
}
int main()
{
int num_group;
cin >> num_group;
while (num_group--)
{
int n, k;
cin >> n >> k;
vector<int> heights;
for (int h; n--;)
{
cin >> h;
heights.push_back(h);
}
// io done
if (IsReachable(heights, k))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}