Program prog;
Uses crt;
var a: array [1..100] of integer;
n,i, k,s: integer;
begin
clrscr; randomize;
write('N = ');
readln(n);
write('k = ');
readln(k);
for i:=1 to n do
begin
a[i]:= random(50);
write(a[i],' ');
end;
writeln;writeln;
for i:=n downto (n-k+1) do
s:=a[i]+s;
writeln('Sum = ', s);
end.