Cod sursa(job #1663172)

Utilizator Tiberiu02Tiberiu Musat Tiberiu02 Data 25 martie 2016 16:35:14
Problema Tribute Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 1.09 kb
# include <stdio.h>
# include <stdlib.h>

# define MAXM 50001

int lSt[MAXM];
int lDr[MAXM];

int cSt[MAXM];
int cDr[MAXM];

int best( int * st, int * dr, int len, int d ) {
    int Best, i;
    Best = 1;
    for ( i = 2; i < len - d; i ++ ) {
        if ( st[i - 1] + dr[i + d] < st[Best - 1] + dr[Best + d] )
            Best = i;
        printf( "%d %d %d %d\n", st[i - 1] + dr[i + d], st[Best - 1] + dr[Best + d], Best, i );
    }

    return Best;
}

int main() {
    FILE *fin = fopen( "tribut.in", "r" ), *fout = fopen( "tribut.out", "w" );

    int n, dx, dy, i, j, l, c;

    fscanf( fin, "%d%d%d", &n, &dx, &dy );

    for ( i = 0; i < n; i ++ ) {
        fscanf( fin, "%d%d", &l, &c );

        lSt[l] ++;
        lDr[l] ++;

        cSt[c] ++;
        cDr[c] ++;
    }

    for ( i = 0; i <= MAXM; i ++ ) {
        lSt[i] += lSt[i - 1];
        lDr[MAXM - i] += lDr[MAXM - i + 1];

        cSt[i] += cSt[i - 1];
        cDr[MAXM - i] += cDr[MAXM - i + 1];
    }

    fprintf( fout, "%d %d\n", best( lSt, lDr, 10, dx ), best( cSt, cDr, 10, dy ) );

    fclose( fin );
    fclose( fout );
    return 0;
}