Pagini recente » Cod sursa (job #2579356) | Cod sursa (job #3241194) | Cod sursa (job #3229705) | Cod sursa (job #11003) | Cod sursa (job #30796)
Cod sursa(job #30796)
#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;}