Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program vodaD;
- var
- n, m, i, max: integer;
- a: array [1 .. 100000] of integer;
- e: boolean;
- function jaga(a: integer): integer;
- begin
- result := a div 10;
- end;
- function getmax: integer;
- var
- i: integer;
- begin
- result := 1;
- for i := 2 to n do
- if a[i] > a[result] then
- result := i;
- end;
- procedure Qsort(l, r: longint);
- var
- i, j, x, y: longint;
- begin
- i := l;
- j := r;
- x := a[l + random(r - l)];
- repeat
- while a[i] > x do
- inc(i);
- while a[j] < x do
- dec(j);
- if i <= j then
- begin
- y := a[i];
- a[i] := a[j];
- a[j] := y;
- inc(i);
- dec(j);
- end;
- until (i > j);
- if l < j then
- Qsort(l, j);
- if i < r then
- Qsort(i, r);
- end;
- procedure goexit;
- var
- i, rez: integer;
- begin
- rez := 0;
- for i := 1 to n do
- inc(rez, a[i]);
- writeln(rez);
- halt(0);
- end;
- begin
- reset(input, 'input.txt');
- rewrite(output, 'output.txt');
- readln(n, m);
- max := 1;
- for i := 1 to n do
- read(a[i]);
- Qsort(1, n);
- while m > 0 do
- begin
- a[max] := jaga(a[max]);
- dec(m);
- if m = 0 then
- goexit;
- if (max < n) and (jaga(a[max]) <= jaga(a[max + 1])) then
- begin
- max := max + 1;
- for i := 1 to max do
- if a[i] > a[max] then
- begin
- a[i] := jaga(a[i]);
- dec(m);
- if m = 0 then
- goexit;
- end;
- end;
- end;
- goexit;
- end.
Add Comment
Please, Sign In to add comment