Cod sursă (job #317715)

Utilizator avatar parket Patrick Adrian Josephs parket IP ascuns
Problemă Domino Compilator c | 1,24 kb
Rundă Arhiva de probleme Status evaluat
Dată 20 oct. 2017 17:58:05 Scor 56
#include <stdio.h>
#include <stdlib.h>
#define N 10000
int v[N][2],stiva[N][2];
int main()
{
    FILE *f1 = fopen("domino.in","r"), *f2 = fopen("domino.out","w");
    int K1,K2,i,n,c=0,vf=0,aux,f;
    fscanf(f1,"%d%d%d",&n,&K1,&K2);
    for(i=0;i<n;i++){
        fscanf(f1,"%d%d",&v[i][0],&v[i][1]);
    }
    c=K2;
    for(i = 0; i<=n;i++){
        f=1;
          while(c>0 && vf>0 && f == 1){
            f = 0;
            if(v[i][0]>stiva[vf][0])
            {
              c--;
              vf--;
              f=1;
            } else if(v[i][1]>stiva[vf][1]) {
              c--;
              vf--;
              f=1;
            }
        }
        stiva[++vf][0]=v[i][0];
        stiva[vf][1] = v[i][1];
    }
    i=0;
    while(K1 != 0 && i<n){
        int maxi=0,max=0,c=i;
        while(c<n){
            c++;
            if(stiva[i][0]+stiva[i][1] > max){
                maxi = i;
                max = stiva[i][0] + stiva[i][1];
            }
        }
        if(stiva[maxi][0] < stiva[maxi][1]){
            aux = stiva[i][0];
            stiva[maxi][0] = stiva[maxi][1];
            stiva[maxi][1] = aux;
            K1--;
        }
        i++;
    }
    for(i = 1; i<=n-K2; i++)
        fprintf(f2,"%d%d",stiva[i][0],stiva[i][1]);
    return 0;
}