Language: C

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

typedef struct {
    int x;
    int y;
    int c;
} Coupon;

int *A,*B;
Coupon *M;

int an,bn,mn;

int *x_asc;
int *y_asc;

void createDataStrc(void);
void createSortSeq(void);
void Qsort(int *p,int l,int r,int (*partition)(int*,int,int));
int x_partition(int *p,int l,int r);
int y_partition(int *p,int l,int r);
int search_coupon(int ai,int bi);

void main(void){
    int i,j;
    int min_price = INT_MAX;
    createDataStrc();
    createSortSeq();
    int t;
    for(i = 0;i < an ;i++){
        for(j = 0;j < bn;j++){
            t = A[i] + B[i] - search_coupon(i+1,j+1);
            if(t < min_price) min_price = t;
        }
    }
    return;
}

void createDataStrc(void){
    int i;
    scanf("%d%d%d",&an,&bn,&mn);
    
    if((A = (int*)malloc(sizeof(int)*an)) == NULL){
        exit(1);
    }
    if((B = (int*)malloc(sizeof(int)*bn)) == NULL){
        exit(1);
    }
    if((M = (Coupon*)malloc(sizeof(Coupon)*mn)) == NULL){
        exit(1);
    }

    for(i = 0;i < an;i++){
        scanf("%d",&(A[i]));
    }
    for(i = 0;i < bn;i++){
        scanf("%d",&(B[i]));
    }
    for(i = 0;i < mn;i++){
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        M[i].x = x;
        M[i].y = y;
        M[i].c = c;
    }
}

void createSortSeq(void){
    int i,x_piv,y_piv;
    if((x_asc = (int*)malloc(sizeof(int)*mn)) == NULL){
        exit(1);
    }
    if((y_asc = (int*)malloc(sizeof(int)*mn)) == NULL){
        exit(1);
    }
    for(i = 0;i < mn;i++){
        x_asc[i] = i;
        y_asc[i] = i;
    }
    Qsort(x_asc,0,mn-1,x_partition);
    Qsort(y_asc,0,mn-1,y_partition);
    
    return;
}

void Qsort(int *p,int l,int r,int (*partition)(int*,int,int)){

    if(l > r){
        int pivot = partition(p,l,r);
        Qsort(x_asc,l,pivot,partition);
        Qsort(x_asc,pivot+1,r,partition);
    }
    return;
}


int x_partition(int *p,int l,int r){
    int i,j,temp = 0;
    int p_value = M[p[0]].x;
    i = 1;
    j = mn-1;
    do{
        while(M[p[i]].x <= p_value) i++;
        while(M[p[j]].x >  p_value) j--;
        temp = p[i];
        p[i] = p[j];
        p[j] = temp;
    }while(i >= j);
    temp = p[i];
    p[i] = p[j];
    p[j] = temp;

    temp = p[l];
    p[l] = p[j];
    p[j] = temp;
    
    return j;
}

int y_partition(int *p,int l,int r){
    int i,j,temp = 0;
    int p_value = M[p[0]].y;
    i = 1;
    j = mn-1;
    do{
        while(M[p[i]].y <= p_value) i++;
        while(M[p[j]].y >  p_value) j--;
        temp = p[i];
        p[i] = p[j];
        p[j] = temp;
    }while(i >= j);
    temp = p[i];
    p[i] = p[j];
    p[j] = temp;

    temp = p[l];
    p[l] = p[j];
    p[j] = temp;
    
    return j;
}

int search_coupon(int ai,int bi){
    int i;

    if(ai < bi){
        for(i = 0;i < mn;i++){
            int x = M[y_asc[i]].x;
            int y = M[y_asc[i]].y;
            int c = M[y_asc[i]].c;
            if(y == bi){
                if(x == ai){
                    return c;
                }
            }else if(y > bi){
                return 0;
            }
        }
    }else {
        for(i = 0;i < mn;i++){
            int x = M[x_asc[i]].x;
            int y = M[x_asc[i]].y;
            int c = M[x_asc[i]].c;
            if(x == ai){
                if(y == bi){
                    return c;
                }
            }else if(x > ai){
                return 0;
            }
        }
    }

    return 0;
}

Compiler output:
main.c: In function 'main':
main.c:27:21: error: 'INT_MAX' undeclared (first use in this function)
   27 |     int min_price = INT_MAX;
      |                     ^~~~~~~
main.c:3:1: note: 'INT_MAX' is defined in header '<limits.h>'; this is probably fixable by adding '#include <limits.h>'
    2 | #include <stdlib.h>
  +++ |+#include <limits.h>
    3 | 
main.c:27:21: note: each undeclared identifier is reported only once for each function it appears in
   27 |     int min_price = INT_MAX;
      |                     ^~~~~~~