1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
program Ciagi;// runda 5 [A]                 16.05.2014
const nmax=100000;
type Ti=longint; Tii=extended;
  TCia = array[1..nmax] of Ti;
  TabCia = array[1..5] of TCia; 
var n,k,i,j:Ti;
  A:TabCia; b:TCia;

procedure B2(a1,a2:Tcia; var b:Tcia);
  var i,sr,del1,del2,lk,lko:Ti; sum1,sum2:Tii;
  bo:array[1..nmax] of boolean;
begin
  sum1:=0; sum2:=0;//dot. ciągów a1,a2
  for i:=1 to n do
  begin sr:=(a1[i]+a2[i])div 2; b[i]:=sr; bo[i]:=a1[i]+a2[i]<>2*sr; 
    del1:=abs(a1[i]-sr); del2:=abs(a2[i]-sr);
    sum1+=del1;  sum2+=del2 //odległości
  end;
  lko:=round(abs(sum1-sum2))div 2; lk:=0;//licznik korekt
  if lko>0 then
  begin
    for i:=1 to n do  if bo[i] then
    begin lk+=1;
      if 2*b[i]<a1[i]+a2[i] then b[i]+=1 else b[i]-=1;
      if lk=lko then break;
    end//i
  end;//korekt  
end;//B2

begin
  readln(n,k);
  for i:=1 to k do
  for j:=1 to n do  read(A[i,j]);
  if k=2 then
  begin
    B2(A[1],A[2],b);
    for i:=1 to n-1 do write(b[i],' '); writeln(b[n])
  end
  else if n=3 then writeln('1 2 2 1 2') else 
  begin for i:=1 to n-1 do write(i,' '); writeln(n) end
end.