-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·53 lines (41 loc) · 913 Bytes
/
Copy pathsol.cpp
File metadata and controls
executable file
·53 lines (41 loc) · 913 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int N, X;
cin >> N >> X;
vector<int> V(N, 0);
for (int i = 0; i < N; ++i)
cin >> V[i];
set<int> S;
bool possible = true;
for (int i = N - 1; i >= 0 && possible; --i)
{
if (i == N - 1)
S.insert(V[i]);
else
{
auto max_below_on_right_it = S.lower_bound(V[i]);
if (max_below_on_right_it != S.begin())
{
--max_below_on_right_it;
int max_below_on_right = *max_below_on_right_it;
if (V[i] + max_below_on_right > X)
possible = false;
}
S.insert(V[i]);
}
}
if (possible)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
solve();
return 0;
}