(File IO): input: eat.in output: eat.out
time limit: 1000 ms space constraints: 131072 KB specific restrictions
Goto ProblemSet
Title Description
After the lambs after class, have to graze on pasture. The village sheep now being featured demonstration village sheep examination, the leaders wanted to see the sheep pasture village.
Village sheep pasture is continuously distributed on each pasture has varying amounts of grazing sheep. The leaders want to see several consecutive pasture, but do not want to see more than
sheep. The village leaders want to see more style village sheep, mostly to visit several pastures as far as possible.
Now, you decide to help the mayor with leaders to visit what some pastures, village leaders and to meet the requirements of.
Enter
the first line an integer
and
, indicates how many consecutive pasture sheep village shares, as well as leaders want to see the maximum number of sheep.
second line
integers, between two integers separated by one space, the i-th ai expressed on the i-th pasture
sheep grazing. Number from
to
。
Output
output line, a total of two numbers, numbers indicate the start and end of the visit numbers, separated by a space. Always take direction from a number of small to large number. In addition, if the possibility of the same length, the smaller number of output starting point for the answer. Data ensure that at least there is an answer.
Sample input
. 5 10
. 6. 3. 1 2. 7
Sample Output
24
Data range limit
% of the data,
;
% of the data,
;
% of the data,
。
Tips
to meet no more than the sum of consecutive
, there is
and
are two possibilities, priority output
to
Ge pasture.
Problem-solving ideas
do a prefix and then violence, combined with a little optimization. .
Code
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
long long n,t,a[100010],maxn,p,q,i;
int main(){
freopen("eat.in","r",stdin);
freopen("eat.out","w",stdout);
scanf("%d%lld",&n,&t);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
a[i]+=a[i-1];
}
i=0,maxn=0;
while(i<n-maxn)
{
i++;
for(int j=i+maxn;j<=n;j++)
{
if(a[j]-a[i-1]<=t)
{
maxn=max(maxn,j-i+1);
p=i;
q=j;
}
else
break;
}
}
printf("%d %d",p,q);
}