Pentru această operație este nevoie să te autentifici.
Cod sursă (job #317713)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Domino | Compilator | c | 1,05 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 20 oct. 2017 17:54:08 | 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;
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++){
while(c>0 && vf>0 && v[i][0]+v[i][1]>=stiva[vf][0]+stiva[vf][1]){
vf--;
c--;
}
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;
}