-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersaforsanta.java
More file actions
45 lines (43 loc) · 1.34 KB
/
Versaforsanta.java
File metadata and controls
45 lines (43 loc) · 1.34 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
import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Versaforsanta {
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int s=sc.nextInt();
int[] arr=new int[n];
long total=0;
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
total+=arr[i];
// total+=arr[i];
}
if(total<=s) System.out.println(0);
else{int max=0;
int index=-1;
for(int i=0;i<n;i++){
if(arr[i]>max){
max=arr[i];
index=i;
}
if(s<arr[i]) {
if(i==n-1 && arr[i]-s<=max){
System.out.println(index+1);
break;
}
else if(i+1<n && arr[i]+arr[i+1]-s<=max){
System.out.println(index+1);
break;
}
}
else s-=arr[i];
}
}
}
}
}