Cod sursa(job #1774434)

Utilizator marcelamarcela marcela Data 8 octombrie 2016 22:42:02
Problema Orase Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <stdio.h>
#include <stdlib.h>

int main(){
    FILE *fin, *fout;
    int n, m, i, d, l, dsmax, ddmax;

    fin = fopen( "orase.in", "r");
    fscanf ( fin, "%d%d", &m, &n);
    dsmax = 0;
    ddmax = 0;
    for ( i = 0; i < n; i++){
        fscanf ( fin, "%d%d", &d, &l);
        if (d > 0){
            if (dsmax < d + l)
                dsmax = d + l;
        }
        if (d < m){
            if (ddmax < m - d + l)
                ddmax = m - d + l;
        }
    }
    fclose(fin);

    fout = fopen ("orase.out", "w");
    fprintf(fout, "%d", dsmax + ddmax - m);
    fclose(fout);
    return 0;
}