-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREVSORT.java
34 lines (34 loc) · 1002 Bytes
/
REVSORT.java
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
import java.util.*;
class REVSORT {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();
while(tc-->0)
{
int n = sc.nextInt();
int x = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int tSum =0, lsum = arr[0], start =0, end =0;
boolean sorted = true;
for (int i = 1; i < n; i++) {
if(arr[i]<=arr[i-1])
{
sorted = false;
end = i;
lsum+=arr[i];
}
else{
lsum=arr[i];
start=i;
end=i;
}
tSum = Math.max(lsum,tSum);
}
if(sorted||tSum<=x) System.out.println("YES");
else System.out.println("NO");
}
}
}