{ Delphi } // // Problem : Wisemen // Contest : UOI-2007 (Kremenchug) // Type : Solution // Date : March, 28th, 2007 // Version : 1.0 // Author : Andriy Stasyuk // Language : Pascal // Compiler : Delphi 7 // Algorithm: Author Solution // program wisemen; {$APPTYPE CONSOLE} const maxN = 1000000; maxM = 1000000; maxK = 1000000; Inf = maxLongint; var f: text; N{men}, M{caps}, K{colors}, i, minManDiff: longint; colorTotal, colorWorn: array [1..maxK] of longint; manCap, manDiff: array [1..maxN] of longint; needSpace: boolean; begin assign(f, 'wisemen.dat'); reset(f); readln(f, N, M, K); for i := 1 to K do begin read(f, colorTotal[i]); colorWorn[i] := 0; end; for i := 1 to N do begin read(f, manCap[i]); inc(colorWorn[manCap[i]]); end; close(f); minManDiff := Inf; for i := 1 to N do if M - colorTotal[manCap[i]] < N then begin manDiff[i] := (M - N) - (colorTotal[manCap[i]] - colorWorn[manCap[i]]); if minManDiff > manDiff[i] then minManDiff := manDiff[i]; end else manDiff[i] := Inf; needSpace := false; assign(f, 'wisemen.sol'); rewrite(f); if minManDiff = Inf then writeln(f, 0) else begin for i := 1 to N do if manDiff[i] = minManDiff then begin if needSpace then write(f, ' '); write(f, i); needSpace := true; end; writeln(f); writeln(f, minManDiff + 1); end; close(f); end.