Advertisement
Guest User

Untitled

a guest
Aug 16th, 2011
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.96 KB | None | 0 0
  1. program solution;
  2.  
  3. {$APPTYPE CONSOLE}
  4. {MODE DELPHI}
  5. {$MAXSTACKSIZE 1000000000}
  6. {O-,R+,Q+}
  7. {$O+,R-,Q-}
  8.  
  9. uses
  10.   SysUtils,
  11.   Math;
  12.  
  13. const
  14.   inf = round(3e18);
  15.  
  16. var
  17.   n, k, i : integer;
  18.   s, ans : int64;
  19.   a : array[0..2000002] of integer;
  20.   sum, gsum : array[0..2000002] of int64;
  21.  
  22. begin
  23.   //assign(input, 'input.txt'); reset(input);
  24.   //assign(output, 'output.txt'); rewrite(output);
  25.   read(n);
  26.   for i := 1 to 2 * n do
  27.     read(a[i]);
  28.   for i := 1 to 2 * n do
  29.     sum[i] := sum[i - 1] + a[i];
  30.   for i := 2 * n downto 1 do
  31.     gsum[i] := gsum[i + 2] + a[i];
  32.   ans := inf;
  33.   for i := 2 to 2 * n do begin
  34.     if 2 * n - i < n - 1 then
  35.       break;
  36.     if i = 2 then begin
  37.       ans := min(ans, (a[1] + a[2]) * (gsum[3] + a[1]));
  38.       continue;
  39.     end;
  40.     if i - 2 < n - 1 then
  41.       s := sum[i - 1] - sum[1] + gsum[2 * i - 1]
  42.     else
  43.       s := sum[n] - sum[1];
  44.     ans := min(ans, (a[1] + a[i]) * (s + a[1]));
  45.   end;
  46.   writeln(ans);
  47. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement