Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.81 KB | None | 0 0
  1. var fin,fout: text;
  2.     a: array [1..10000] of longint;
  3.     i,j,n:integer;
  4.     b,d: longint;
  5.     ofl,fl: boolean;  
  6. begin
  7.   assign(fin,'input.txt');
  8.   assign(fout,'output.txt');
  9.   reset(fin);
  10.   rewrite(fout);
  11.  
  12.   read(fin,d);
  13.   read(fin,n);
  14.   ofl:=false;
  15.   for i:=1 to (n - 2) do
  16.   begin
  17.     read(fin,a[i]);
  18.     d:=d - a[i];
  19.   end;
  20.   for i:=1 to (d-1) do
  21.   begin
  22.     fl:=true;
  23.     for j:=1 to (n-2) do
  24.       if i=a[j] then fl:=false;
  25.     if fl=true then
  26.     begin
  27.       b:=d-i;
  28.       fl:=true;
  29.       for j:=1 to (n-2) do
  30.         if b=a[j] then fl:=false;
  31.       if (b=i) then fl:=false;
  32.       if fl=true then
  33.       begin
  34.         write(fout,i);
  35.         ofl:=true;
  36.         break;
  37.       end;
  38.     end;
  39.   end;
  40.   if ofl=false then
  41.     write(fout,-1);
  42.  
  43.   close(fin);
  44.   close(fout);
  45. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement