Moving the Kings

  • + 0 comments
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    struct points{
        long int x,y;
    };
    
    long int max(long int a,long int b){
        long int res;
            if(a<0) a=-a;
            if(b<0) b=-b;
        res=a>=b?a:b;
        return res;
    }
    
    int main() {
    
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n,q;
        scanf("%d %d",&n,&q);
        struct points *Kings=(struct points*)malloc(n*sizeof(struct points));
        for(int i=0;i<n;i++){
            scanf("%ld %ld",&(Kings[i]->x),&(Kings[i]->y));
        }
        
        long int qx,qy;
        for(int i=0;i<q;i++){
            scanf("%ld %ld",&qx,&qy);
            long int res=0;
            for(int j=0;j<n;j++){
                //min(Kings[j]->x,Kings[j]->y,qx,qy)
                res+=max((Kings[j]->x)-x,(Kings[j]->y)-y);
            }
            printf("%ld",res);
        }
        
        return 0;
    }
    

    Problem's in here

    struct points *Kings=(struct points*)malloc(n*sizeof(struct points));
    

    and here

    scanf("%ld %ld",&(Kings[i]->x),&(Kings[i]->y));
    

    please help me out