Pagini recente » Cod sursa (job #1680395) | Cod sursa (job #3144829) | Cod sursa (job #968967) | Cod sursa (job #2961644) | Cod sursa (job #131324)
Cod sursa(job #131324)
type vector=array[1..100] of integer;
mat=array[1..10,1..10] of integer;
var i,n,m,r,c,j,aux1,aux2,s:integer;
sl,sc,poz:vector;
a:mat;
ok:boolean;
f:text;
procedure cit_f;
var f:text;
begin
assign(f,'elimin.in');
reset(f);
readln(f,m,n,r,c);
for i:=1 to m do
begin
for j:=1 to n do
read(f,a[i,j]);
readln(f);
end;
end;
function s_lin(l:integer):integer;
var s,i:integer;
begin
s:=0;
for i:=1 to n do
s:=s+a[l,i];
s_lin:=s;
end;
function s_col(c:integer):integer;
var s,i:integer;
begin
s:=0;
for i:=1 to m do
s:=s+a[i,c];
s_col:=s;
end;
BEGIN
cit_f;
for i:=1 to m do
poz[i]:=i;
for i:=1 to m do
sl[i]:=s_lin(i);
repeat
ok:=true;
for i:=1 to m-1 do
if sl[i]>sl[i+1] then
begin
aux1:=sl[i];
aux2:=sl[i+1];
sl[i]:=aux2;
sl[i+1]:=aux1;
ok:=false;
aux1:=poz[i];
aux2:=poz[i+1];
poz[i]:=aux2;
poz[i+1]:=aux1;
end;
until ok;
s:=0;
for i:=1 to m do
for j:=1 to n do
s:=s+a[i,j];
for i:=1 to r do
begin
s:=s-sl[i];
for j:=1 to n do
a[poz[i],j]:=0;
end;
for i:=1 to n do
sc[i]:=s_col(i);
repeat
ok:=true;
for i:=1 to n-1 do
if sc[i]>sc[i+1] then
begin
aux1:=sc[i];
aux2:=sc[i+1];
sc[i]:=aux2;
sc[i+1]:=aux1;
ok:=false;
end;
until ok;
for i:=1 to c do
s:=s-sc[i];
assign(f,'elimin.out');
rewrite(f);
write(f,s);
close(f);
END.