杭电2430.Beans,我提交总错误,可测试数据全对!能帮我看看哪错了不?
#include<iostream>#include<string.h>
#include<stdio.h>
using namespace std;
long int c[1000005],n;
long int a[1000005];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x)
{
int s=0;
while(x>0)
{
s+=c[x];
x-=lowbit(x);
}
return s;
}
void add(int x, int add)
{
while(x<=n)
{
c[x]+=add;
x+=lowbit(x);
}
}
int main()
{
int t,p,k,sumc,y,cc,i,q=1;
cin>>t;
while(t--)
{
cin>>n>>p>>k;
memset(c,0,sizeof(c));
for(i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
add(i,a[i]);
}
cout<<"Case "<<q++<<": ";
sumc=sum(n);
cc=sumc/p;
y=sumc%p;
if(y>=k)
cout<<"-1"<<endl;
else
cout<<cc<<endl;
}
return 0;
}