in Problem code ZOZ (magic elements), can anyone please tell me how to successfully pass the original conctraints subtask.
this is my code
#include
using namespace std;
int main() {
int ar[1000],N,K,T,i=1,j;
cin>>T;
int validpos(int[],int,int);
while(i<=T)
{
cin>>N;cout<<" ";cin>>K;
for(j=0;j<N;j++)
cin>>ar[j];
validpos(ar,N,K);
i++;
}
return 0;
}
int validpos(int a[],int N,int K)
{ int sum=0,sum2,count=0;
for(int j=0;j<N;j++)
{
sum=sum+a[j];
}
//to find valid positions
for(int j=0;j<N;j++)
{
sum2=sum-a[j];
if((a[j]+K)>sum2)
count++;
}
cout<<"\n"<<count;
}
constraints * 1 ≤ T ≤ 100,000
- 1 ≤ N ≤ 100,000
- 1 ≤ K ≤ 109
- 1 ≤ Ai ≤ 104 for each valid i
- 1 ≤ sum of N over all test cases ≤ 100,000