Language: C

#include <stdio.h>
#include <stdlib.h>
void usort(long *a,long n){
    long *store;
    long hf=n,unit=1,a1,a2;
    store=malloc((long)sizeof(long)*n*2);
    for (int i=0;i<n;i++){
      store[i][0]=a[i][0];
      store[i][1]=a[i][1];
    }
    while (hf>1){
        if (hf==2){
            hf=(hf+1)/2;
            for (long i=0;i<hf;i++){
                a1=0;
                a2=0;
                while (a1+a2<2*unit && 2*i*unit+a1+a2<n){
                    if (a1==unit){
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                    else if (a2==unit || (2*i+1)*unit+a2==n){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else {
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                }
            }
            for (long i=0;i<n;i++) a[i]=store[i];
            break;
        }
        else if (hf%2){
            hf=(hf+1)/2;
            for (long i=0;i<hf-1;i++){
                a1=0;
                a2=0;
                while (a1+a2<2*unit && 2*i*unit+a1+a2<n){
                    if (a1==unit){
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                    else if (a2==unit || (2*i+1)*unit+a2==n){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else {
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                }
            }
        }
        else {
            hf=(hf+1)/2;
            for (long i=0;i<hf;i++){
                a1=0;
                a2=0;
                while (a1+a2<2*unit && 2*i*unit+a1+a2<n){
                    if (a1==unit){
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                    else if (a2==unit || (2*i+1)*unit+a2==n){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
                        store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
                      store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
                        a1++;
                    }
                    else {
                        store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
                      store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
                        a2++;
                    }
                }
            }
        }
        unit*=2;
        for (long i=0;i<n;i++) a[i]=store[i];
    }
    free(store);
    return;
}

int main(){
    long n,m,*d,cost=0;
    scanf("%lld%lld",&n,&m);
    d=malloc((long)sizeof(long)*n*2);
    for (long i=0;i<n;i++) scanf("%lld%lld",&d[i][0],&d[i][1]);
    usort(d,n);
    for (long i=0;i<n;i++){
      if (m>d[i][1]){
        cost+=d[i][0]*d[i][1];
        m-=d[i][1];
      }
      else {
        cost+=d[i][0]*m;
        break;
      }
    }
  printf("%lld\n",cost);
    free(d);
    return 0;
}


Compiler output:
main.c: In function 'usort':
main.c:8:15: error: subscripted value is neither array nor pointer nor vector
    8 |       store[i][0]=a[i][0];
      |               ^
main.c:8:23: error: subscripted value is neither array nor pointer nor vector
    8 |       store[i][0]=a[i][0];
      |                       ^
main.c:9:15: error: subscripted value is neither array nor pointer nor vector
    9 |       store[i][1]=a[i][1];
      |               ^
main.c:9:23: error: subscripted value is neither array nor pointer nor vector
    9 |       store[i][1]=a[i][1];
      |                       ^
main.c:19:46: error: subscripted value is neither array nor pointer nor vector
   19 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                              ^
main.c:19:68: error: subscripted value is neither array nor pointer nor vector
   19 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                                                    ^
main.c:20:44: error: subscripted value is neither array nor pointer nor vector
   20 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                            ^
main.c:20:66: error: subscripted value is neither array nor pointer nor vector
   20 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                                                  ^
main.c:24:46: error: subscripted value is neither array nor pointer nor vector
   24 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                              ^
main.c:24:64: error: subscripted value is neither array nor pointer nor vector
   24 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                                                ^
main.c:25:44: error: subscripted value is neither array nor pointer nor vector
   25 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                            ^
main.c:25:62: error: subscripted value is neither array nor pointer nor vector
   25 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                                              ^
main.c:28:48: error: subscripted value is neither array nor pointer nor vector
   28 |                     else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
      |                                                ^
main.c:28:66: error: subscripted value is neither array nor pointer nor vector
   28 |                     else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
      |                                                                  ^
main.c:29:46: error: subscripted value is neither array nor pointer nor vector
   29 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                              ^
main.c:29:64: error: subscripted value is neither array nor pointer nor vector
   29 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                                                ^
main.c:30:44: error: subscripted value is neither array nor pointer nor vector
   30 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                            ^
main.c:30:62: error: subscripted value is neither array nor pointer nor vector
   30 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                                              ^
main.c:34:46: error: subscripted value is neither array nor pointer nor vector
   34 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                              ^
main.c:34:68: error: subscripted value is neither array nor pointer nor vector
   34 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                                                    ^
main.c:35:44: error: subscripted value is neither array nor pointer nor vector
   35 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                            ^
main.c:35:66: error: subscripted value is neither array nor pointer nor vector
   35 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                                                  ^
main.c:50:46: error: subscripted value is neither array nor pointer nor vector
   50 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                              ^
main.c:50:68: error: subscripted value is neither array nor pointer nor vector
   50 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                                                    ^
main.c:51:44: error: subscripted value is neither array nor pointer nor vector
   51 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                            ^
main.c:51:66: error: subscripted value is neither array nor pointer nor vector
   51 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                                                  ^
main.c:55:46: error: subscripted value is neither array nor pointer nor vector
   55 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                              ^
main.c:55:64: error: subscripted value is neither array nor pointer nor vector
   55 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                                                ^
main.c:56:44: error: subscripted value is neither array nor pointer nor vector
   56 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                            ^
main.c:56:62: error: subscripted value is neither array nor pointer nor vector
   56 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                                              ^
main.c:59:48: error: subscripted value is neither array nor pointer nor vector
   59 |                     else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
      |                                                ^
main.c:59:66: error: subscripted value is neither array nor pointer nor vector
   59 |                     else if (a[(2*i+1)*unit+a2][0]>a[2*i*unit+a1][0]){
      |                                                                  ^
main.c:60:46: error: subscripted value is neither array nor pointer nor vector
   60 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                              ^
main.c:60:64: error: subscripted value is neither array nor pointer nor vector
   60 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                                                ^
main.c:61:44: error: subscripted value is neither array nor pointer nor vector
   61 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                            ^
main.c:61:62: error: subscripted value is neither array nor pointer nor vector
   61 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                                              ^
main.c:65:46: error: subscripted value is neither array nor pointer nor vector
   65 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                              ^
main.c:65:68: error: subscripted value is neither array nor pointer nor vector
   65 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                                                    ^
main.c:66:44: error: subscripted value is neither array nor pointer nor vector
   66 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                            ^
main.c:66:66: error: subscripted value is neither array nor pointer nor vector
   66 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                                                  ^
main.c:79:46: error: subscripted value is neither array nor pointer nor vector
   79 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                              ^
main.c:79:68: error: subscripted value is neither array nor pointer nor vector
   79 |                         store[2*i*unit+a1+a2][0]=a[(2*i+1)*unit+a2][0];
      |                                                                    ^
main.c:80:44: error: subscripted value is neither array nor pointer nor vector
   80 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                            ^
main.c:80:66: error: subscripted value is neither array nor pointer nor vector
   80 |                       store[2*i*unit+a1+a2][1]=a[(2*i+1)*unit+a2][1];
      |                                                                  ^
main.c:84:46: error: subscripted value is neither array nor pointer nor vector
   84 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                              ^
main.c:84:64: error: subscripted value is neither array nor pointer nor vector
   84 |                         store[2*i*unit+a1+a2][0]=a[2*i*unit+a1][0];
      |                                                                ^
main.c:85:44: error: subscripted value is neither array nor pointer nor vector
   85 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |                                            ^
main.c:85:62: error: subscripted value is neither array nor pointer nor vector
   85 |                       store[2*i*unit+a1+a2][1]=a[2*i*unit+a1][1];
      |