TOPIC

PROBLEM 1601 - URI Fórum 1.0

beecrowd asked 9 years ago

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • gamamal replied 8 years ago

    I get WA at 20%, no idea why. Any help?

    #include <cstdio>
    #include <cstdlib>
    
    int compare (const void * a, const void * b)
    {
       return ( *(int*)a - *(int*)b );
    }
    
    int main(){
      int a[1000];
      int b,c,d,e;
      long long s,m;
      while(scanf("%d",&b) != EOF){
        for(c=0;c<b;c++){
          scanf("%d",&a[c]);
        }
        for(c=b;c<1000;c++){
          a[c]=1001;
        }
        qsort(a,1000,sizeof(int),compare);
        s=0;
        for(c=1;c<b;c++){
          for(d=0;d<c;d++){
        s=s+a[c]-a[d];
          }
        }
        m=s;
        for(c=0;c<b;c++){
          for(d=0;d<c;d++){
        s=s+a[c]-a[d];
          }
          for(d=c+1;d<b;d++){
        s=s-(a[d]-a[c]);
          }
          if(m>s){
        m=s;
          }
        }
        printf("%lld\n",m); 
      }
    }