avatar
Untitled

Guest 2.3K 2nd Mar, 2019

uses crt;
const fi='D:\fp\text\PTHUONG.INP'; fo='D:\fp\text\PTHUONG.OUT';
var a,x,b:array[0..100] of byte;
    n,k,i,j,s,m,max,kq:longint;

function kt:boolean;
var d,i:longint;
begin
  d:=0;
  for i:=2 to k do
    if x[i]=x[i-1]+1 then begin
      inc(d);
      if d=2 then exit(false);
    end else d:=0;
  exit(true);
end;

BEGIN
  clrscr;
  assign(input,fi); reset(input);
  assign(output,fo); rewrite(output);
  readln(n);
  for i:=1 to n do readln(a[i]);
  max:=low(longint);
  while k<>n do begin
    inc(k);
    for i:=1 to k do x[i]:=i;
    repeat
      s:=0;
      //for i:=1 to k do write(x[i],' '); writeln;
      if kt then begin
        for i:=1 to k do s:=s+a[x[i]];
        if s > max then begin
          max:=s;
          for i:=1 to k do b[i]:=x[i];
          m:=k; kq:=s;
        end;
      end;
      i:=k;
      while (i>0) and (x[i]=n-k+i) do dec(i);
      if i>0 then begin
        inc(x[i]);
        for j:=i+1 to k do x[j]:=x[j-1]+1;
      end;
    until i=0;
  end;
  writeln(kq);
  for i:=1 to m do writeln(b[i]);
  readln;
END.
Pascal
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data