Cod sursa(job #30796)

Utilizator razvi9Jurca Razvan razvi9 Data 15 martie 2007 09:01:17
Problema Elimin Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include<stdio.h>
int a[150][150],n,m,i,j,r,col;
long c[150][2],l[150][2],s;
int poz(long a[][2],int p,int u)
{int sp=0,su=-1,k=p;
 long aux;
 while(p!=u){
 if(a[p][0]>a[u][0]) {aux=a[u][0];a[u][0]=a[p][0];a[p][0]=aux;
                aux=a[u][1];a[u][1]=a[p][1];a[p][1]=aux;
				k=u;aux=sp;sp=-su;su=-sp;}
 p=p+sp;u=u+su;}
 return k;}
void qsort(long a[][2],int p,int u)
{if(u-p<=0) return;
 if(u-p==1) {if(a[p][0]>a[u][0]){ long aux=a[p][0];a[p][0]=a[u][0];a[u][0]=aux;
                                 aux=a[p][1];a[p][1]=a[u][1];a[u][1]=aux;} return;}
 int k=poz(a,p,u);
 qsort(a,p,k-1);
 qsort(a,k+1,u);}
int main()
{freopen("elimin.in","r",stdin);
 freopen("elimin.out","w",stdout);
 scanf("%d %d %d %d",&n,&m,&r,&col);
 for(i=1;i<=n;i++){l[i][1]=i;
  for(j=1;j<=n;j++)
  {scanf("%d",&a[i][j]);
   s=s+a[i][j];
   c[j][0]=c[j][0]+a[i][j];
   l[i][0]=l[i][0]+a[i][j];}}
 qsort(l,1,n);
 for(i=1;i<=r;i++)
 {s=s-l[i][0];
  for(j=1;j<=m;j++)
   c[j][0]=c[j][0]-a[l[i][1]][j];}
 qsort(c,1,m);
 for(i=1;i<=col;i++)
  s=s-c[i][0];
 printf("%ld",s);
 fclose(stdout);
 return 0;}