ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Give me test nomber 7 for problem 1244
Posted by coder 29 Aug 2005 17:08
program prob_1244;
{$APPTYPE CONSOLE}
const
     max_n  = 100;
     max_m = 1000;
     max_v = max_n * max_m;
var
    b: array[0..max_v]of boolean;
    y: array[0..max_v]of longint;
    x: array[1..max_n]of longint;
    v, n , q, w, i, j: longint;
begin
   assign(input,'card.in');reset(input);
   assign(output,'card.out');rewrite(output);
    read(q);
    read(n);
    y[0] := max_n + 1;
    w := 0;
    for i := 1 to n do begin
        read(v);
        x[i] := v;
        for j := 0 to max_v - v do begin
            if (y[j] > 0)and(y[j] <> i)then begin
                b[j + v] := b[j] or (y[j + v] > 0);
                y[j + v] := i;
            end;
        end;
        inc(w, v);
    end;
    if (y[q] = 0)   then writeln(0)
    else if b[q] or (w = q)then writeln(-1)
    else begin
         while q > 0  do begin
              v := q;
              dec(q, x[y[v]]);
              x[y[v]] := -1;
         end;
         for  i := 1 to n do if x[i] <> -1 then write(i,' ');
         writeln;
    end;
end.