SORT5

#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;
}

9 comments:

  1. It is getting only 60% evaluate da

    ReplyDelete
  2. Update 2020:
    by putting (check==0 || temp2==0 )
    we can get 80% evaluation.

    ReplyDelete
  3. #include
    void 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;
    }

    ReplyDelete
    Replies
    1. this only gets me 80% can you post the full program please

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. #include
    void 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

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...