ALIEN
#include<iostream>
#include<cstdio>
using namespace std;
main()
{
int t;
cin>>t;
while(t--)
{
int i,n,m,min=100000000,j=0,sum=0;scanf("%d%d",&n,&m);int arr[n];
for(i=0;i<n;i++) scanf("%d",&arr[i]);
int ct=0;
int hld=0;
for(i=0;i<n;i++)
{
sum+=arr[i];ct++;for(;sum>m;) {sum-=arr[j++];ct--;}
if((min>sum)&&(ct==hld)){min=sum;}//if(max==m) break;
else if(ct>hld){min=sum;hld=ct;}
}
printf("%d %d\n",min,hld);
}
return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
main()
{
int t;
cin>>t;
while(t--)
{
int i,n,m,min=100000000,j=0,sum=0;scanf("%d%d",&n,&m);int arr[n];
for(i=0;i<n;i++) scanf("%d",&arr[i]);
int ct=0;
int hld=0;
for(i=0;i<n;i++)
{
sum+=arr[i];ct++;for(;sum>m;) {sum-=arr[j++];ct--;}
if((min>sum)&&(ct==hld)){min=sum;}//if(max==m) break;
else if(ct>hld){min=sum;hld=ct;}
}
printf("%d %d\n",min,hld);
}
return 0;
}
No comments:
Post a Comment