-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlien.java
49 lines (47 loc) · 985 Bytes
/
Alien.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ques;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Alien {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t>0){
String[] s=new String[2];
s=br.readLine().split(" ");
int station=Integer.parseInt(s[0]);
int people=Integer.parseInt(s[1]);
String[] ss=new String[station];
int[] arr=new int[station];
ss=br.readLine().split(" ");
for(int i=0;i<station;i++)
arr[i]=Integer.parseInt(ss[i]);
int max=0,sum=0,i=0;
int maxi=0,sumi=0;
int p=0;
while(i<station){
people-=arr[i];
sum+=arr[i];
max++;
if(people<0){
while(people<0){
people+=arr[p];
sum-=arr[p];
max--;
p++;
}
}
if(max>maxi){
maxi=max;
sumi=sum;
}
else if(max==maxi){
if(sumi>sum)
sumi=sum;
}
i++;
}
System.out.println(sumi+" "+maxi);
t--;
}
}
}