#include<stdio.h>
long long min(long long x,long long y){
if(x<y)
return x;
return y;
}
int main(){
long long n,k,ar[100009],br[100009],i,j,sum1[100000],sum2[100000],u;
scanf("%lld %lld",&n,&k);
for(i=0;i<n;i++){
scanf("%lld",&ar[i]);
}
for(i=0;i<n;i++){
scanf("%lld",&br[i]);
}
sum1[0]=ar[0];sum2[0]=br[0];
if(sum1[0]>k && sum2[0]>0){
printf("0 0\n");
}else{
for(i=1;i<n;i++){
sum1[i]=min(sum1[i-1]+ar[i],sum2[i-1]+ar[i-1]+ar[i]);
sum2[i]=min(sum2[i-1]+br[i],sum1[i-1]+br[i-1]+br[i]);
if(sum1[i]>k && sum2[i]>k)
break;
}
for(j=i-1;j>=0;j--){
u=min(sum1[j],sum2[j]);
if(u<=k){
printf("%lld %lld\n",j+1,u);
break;
}
}
}
return 0;
}
long long min(long long x,long long y){
if(x<y)
return x;
return y;
}
int main(){
long long n,k,ar[100009],br[100009],i,j,sum1[100000],sum2[100000],u;
scanf("%lld %lld",&n,&k);
for(i=0;i<n;i++){
scanf("%lld",&ar[i]);
}
for(i=0;i<n;i++){
scanf("%lld",&br[i]);
}
sum1[0]=ar[0];sum2[0]=br[0];
if(sum1[0]>k && sum2[0]>0){
printf("0 0\n");
}else{
for(i=1;i<n;i++){
sum1[i]=min(sum1[i-1]+ar[i],sum2[i-1]+ar[i-1]+ar[i]);
sum2[i]=min(sum2[i-1]+br[i],sum1[i-1]+br[i-1]+br[i]);
if(sum1[i]>k && sum2[i]>k)
break;
}
for(j=i-1;j>=0;j--){
u=min(sum1[j],sum2[j]);
if(u<=k){
printf("%lld %lld\n",j+1,u);
break;
}
}
}
return 0;
}
No comments:
Post a Comment