-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeedrun.cpp
86 lines (79 loc) · 1.98 KB
/
Speedrun.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Monster
{
int position;
int health;
};
// Function to check if Chef can win given a specific bomb position
bool canChefWin(int K, vector<Monster> &monsters)
{
sort(monsters.begin(), monsters.end(), [](const Monster &a, const Monster &b)
{ return a.position < b.position; });
int time = 0;
for (auto &monster : monsters)
{
int distance = monster.position - time;
if (distance <= 0)
{
return false; // Monster reaches Chef
}
time += monster.health; // Spend health seconds to kill the monster
}
return true; // All monsters are killed before reaching Chef
}
int main()
{
int T;
cin >> T;
while (T--)
{
int N, K;
cin >> N >> K;
vector<int> positions(N);
vector<int> healths(N);
vector<Monster> monsters(N);
for (int i = 0; i < N; i++)
{
cin >> positions[i];
}
for (int i = 0; i < N; i++)
{
cin >> healths[i];
}
for (int i = 0; i < N; i++)
{
monsters[i] = {positions[i], healths[i]};
}
bool result = false;
// Try placing the bomb at each monster's position
for (int i = 0; i < N; i++)
{
int bombPosition = positions[i];
vector<Monster> remainingMonsters;
for (auto &monster : monsters)
{
if (monster.position < bombPosition - K || monster.position > bombPosition + K)
{
remainingMonsters.push_back(monster);
}
}
if (canChefWin(K, remainingMonsters))
{
result = true;
break;
}
}
if (result)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
return 0;
}