-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFG.java
More file actions
53 lines (48 loc) · 1.44 KB
/
GFG.java
File metadata and controls
53 lines (48 loc) · 1.44 KB
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
import java.util.*;
import java.lang.*;
import java.io.*;
class Pair{
int f,l;
Pair(int f, int l) {
this.f = f;
this.l = l;
}
}
class GFG {
public static void main (String[] args) {
HashMap<Integer, Pair> hm = new HashMap<>();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int min = Integer.MAX_VALUE;
while(t-- > 0) {
int n = sc.nextInt();
int x = sc.nextInt();
int a[] = new int[n];
int b[] = new int[n];
int maxIndex = -1, mSize = Integer.MAX_VALUE;
boolean flag = false;
for(int i=0;i<n;i++) {
a[i] = sc.nextInt();
if(i==0) b[i] = a[i];
else b[i] = b[i-1] + a[i];
if(b[i] > x && !flag) { maxIndex = i;
flag = true;
}
}
//System.out.println(Arrays.toString(b));
//System.out.println(maxIndex);
for(int i= maxIndex;i<n;i++) {
mSize = Math.min(mSize, i+1);
for(int j = i-1;j>=0;j--) {
int diff = b[i] - b[j];
if(diff > x) {
mSize = Math.min(mSize, i-j);
//System.out.println(i + " " + j);
break;
}
}
}
System.out.println(mSize);
}
}
}