forked from arv002-zz/spojcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALIEN - Aliens at the train.cpp
64 lines (46 loc) · 1.02 KB
/
ALIEN - Aliens at the train.cpp
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
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
using namespace std;
long long sum=0;
int main()
{
long long t;
cin>>t;
while(t--)
{
long long N,M;
cin>>N>>M;
long long a[N],i,k=0,j=0,current=0,MIN1=0,MIN2=INT_MAX;
for(i=0; i<N; i++)
cin>>a[i];
for(i=0; i<N; i++)
{
if(current+a[i]<=M)
{
current+=a[i];
k++;
}
else
{
current+=a[i];
k++;
while(current>M)
{
current-=a[j];
k--;
j++;
}
}
if(k>MIN1)
{
MIN1=k;
MIN2=current;
}
else if(MIN1==k)
{
if(MIN2>current)
MIN2=current;
}
}
cout<<MIN2<<" "<<MIN1<<"\n";
}
}