#include <stdio.h>
void sort(int a[],int n)
{int t,i,j; for(i=0;i<n;i++)for(j=0;j<n-i-1;j++)if(a[i]>a[i+1]){t=a[i]; a[i]=a[i+1]; a[i+1]=t;}}
int main() {
int A[100],T,K,N,check=0,i;
scanf("%d",&T);
while(T--)
{ int temp,temp2=0;
check=0;
scanf("%d",&N);
scanf("%d",&K);
for(i=0;i<N;i++) { scanf("%d",&A[i]);} sort(A,N);
for(i=0;i<N;i++)
if(A[i]>=K)
{
temp = A[i]-K;
K+=temp;
temp2 += temp;
check=1;
}
if(check==0)
printf("-1");
else
printf("%d",temp2);
printf("\n");
}
return 0;
}
void sort(int a[],int n)
{int t,i,j; for(i=0;i<n;i++)for(j=0;j<n-i-1;j++)if(a[i]>a[i+1]){t=a[i]; a[i]=a[i+1]; a[i+1]=t;}}
int main() {
int A[100],T,K,N,check=0,i;
scanf("%d",&T);
while(T--)
{ int temp,temp2=0;
check=0;
scanf("%d",&N);
scanf("%d",&K);
for(i=0;i<N;i++) { scanf("%d",&A[i]);} sort(A,N);
for(i=0;i<N;i++)
if(A[i]>=K)
{
temp = A[i]-K;
K+=temp;
temp2 += temp;
check=1;
}
if(check==0)
printf("-1");
else
printf("%d",temp2);
printf("\n");
}
return 0;
}
It is getting only 60% evaluate da
ReplyDeleteUpdate 2020:
ReplyDeleteby putting (check==0 || temp2==0 )
we can get 80% evaluation.
#include
ReplyDeletevoid sort(int a[],int n,int k)
{int t,i,j;
for(i=0;ia[i+1]){
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
int main() {
int A[100],T,K,N,i;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
scanf("%d",&K);
for(i=0;iK)
{
int temp;
temp = A[N-1]-K;
printf("%d",temp);
}
else if (A[N-1] == K)
printf("-1");
else if(A[N-1] < K)
printf("-1");
printf("\n");
}
return 0;
}
100% working
Deletethis only gets me 80% can you post the full program please
DeleteThis comment has been removed by the author.
ReplyDelete#include
ReplyDeletevoid sort(int a[],int n,int k)
{
int t,i,j;
for(i=0;ia[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
int main() {
int A[100],T,K,N,check=0,i;
scanf("%d",&T);
while(T--)
{
int temp,temp2=0;
check=0;
scanf("%d",&N);
scanf("%d",&K);
for(i=0;i=K)
{
temp = A[i]-K;
K+=temp;
temp2 += temp;
check=1;
}
if(temp2==0)
printf("-1");
else
printf("%d",temp2);
printf("\n");
}
return 0;
}
100% working
Haha
ReplyDelete