Cod sursa(job #1774421)

Utilizator marcelamarcela marcela Data 8 octombrie 2016 22:18:13
Problema Orase Scor 10
Compilator c Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <stdio.h>
#include <stdlib.h>

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

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

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