Language: C

#include<stdio.h>
#include<stdlib.h>

struct list { int b, c; };
typedef struct list *listp;

int cmp1(const void *a, const void *b) {
    int d1 = *(int*)a, d2 = *(int*)b;
    if(d1 > d2)         { return 1; }
    else if(d1 == d2)   { return 0; }
    else                { return -1; }
}

int cmp2(const void *a, const void *b) {
    listp d1 = *(listp*)a, d2 = *(listp*)b;
    if(d1->c > d2->c)       { return -1; }
    else if(d1->c == d2->c) { return 0; }
    else                    { return 1; }
}

int main(void) 
{
    int N, M, i, j, cnt;
    scanf("%d %d", &N, &M);
    int *A = (int*)malloc((N+3)*sizeof(int));
    listp *list = (listp*)malloc((M+4)*sizeof(listp));
    for(i = 0; i < M; ++i) {
        list[i] = (listp)malloc(sizeof(struct list));
    }
    for(i = 0; i < N; ++i) {
        scanf("%d", &A[i]);
    }
    for(i = 0; i < M; ++i) {
        scanf("%d %d", &list[i]->b, &list[i]->c);
    }
    qsort(A, N, sizeof(int), cmp1);
    qsort(list, M, sizeof(listp), cmp2);

    /*
    for(i = 0; i < N; ++i) {
        printf("%d ", A[i]);
    }
    printf("\n");
    for(i = 0; i < M; ++i) {
        printf("%d %d\n", list[i]->b, list[i]->c);
    }
    */
    
    cnt = 0;
    for(i = 0; i < M; ++i) {
        for(j = 0; j < list[i]->b; ++j) {
            if(list[i]->c <= A[cnt]) { break; }
            A[cnt++] = list[i]->c;
        }
    }

    long long ans = 0;
    for(i = 0; i < N; ++i) { ans += A[i]; }
    printf("%lld\n", ans);
    return 0;
}#include<stdio.h>
#include<stdlib.h>

struct list { int b, c; };
typedef struct list *listp;

int cmp1(const void *a, const void *b) {
    int d1 = *(int*)a, d2 = *(int*)b;
    if(d1 > d2)         { return 1; }
    else if(d1 == d2)   { return 0; }
    else                { return -1; }
}

int cmp2(const void *a, const void *b) {
    listp d1 = *(listp*)a, d2 = *(listp*)b;
    if(d1->c > d2->c)       { return -1; }
    else if(d1->c == d2->c) { return 0; }
    else                    { return 1; }
}

int main(void) 
{
    int N, M, i, j, cnt;
    scanf("%d %d", &N, &M);
    int *A = (int*)malloc((N+3)*sizeof(int));
    listp *list = (listp*)malloc((M+4)*sizeof(listp));
    for(i = 0; i < M; ++i) {
        list[i] = (listp)malloc(sizeof(struct list));
    }
    for(i = 0; i < N; ++i) {
        scanf("%d", &A[i]);
    }
    for(i = 0; i < M; ++i) {
        scanf("%d %d", &list[i]->b, &list[i]->c);
    }
    qsort(A, N, sizeof(int), cmp1);
    qsort(list, M, sizeof(listp), cmp2);

    /*
    for(i = 0; i < N; ++i) {
        printf("%d ", A[i]);
    }
    printf("\n");
    for(i = 0; i < M; ++i) {
        printf("%d %d\n", list[i]->b, list[i]->c);
    }
    */
    
    cnt = 0;
    for(i = 0; i < M; ++i) {
        for(j = 0; j < list[i]->b; ++j) {
            if(list[i]->c <= A[cnt]) { break; }
            A[cnt++] = list[i]->c;
        }
    }

    long long ans = 0;
    for(i = 0; i < N; ++i) { ans += A[i]; }
    printf("%lld\n", ans);
    return 0;
}

Compiler output:
main.c:61:2: error: stray '#' in program
   61 | }#include<stdio.h>
      |  ^
main.c:61:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
   61 | }#include<stdio.h>
      |          ^
main.c:67:5: error: redefinition of 'cmp1'
   67 | int cmp1(const void *a, const void *b) {
      |     ^~~~
main.c:7:5: note: previous definition of 'cmp1' with type 'int(const void *, const void *)'
    7 | int cmp1(const void *a, const void *b) {
      |     ^~~~
main.c:74:5: error: redefinition of 'cmp2'
   74 | int cmp2(const void *a, const void *b) {
      |     ^~~~
main.c:14:5: note: previous definition of 'cmp2' with type 'int(const void *, const void *)'
   14 | int cmp2(const void *a, const void *b) {
      |     ^~~~
main.c:81:5: error: redefinition of 'main'
   81 | int main(void)
      |     ^~~~
main.c:21:5: note: previous definition of 'main' with type 'int(void)'
   21 | int main(void)
      |     ^~~~