Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program solution;
- {$APPTYPE CONSOLE}
- {MODE DELPHI}
- {$MAXSTACKSIZE 1000000000}
- {O-,R+,Q+}
- {$O+,R-,Q-}
- uses
- SysUtils,
- Math;
- const
- inf = round(3e18);
- var
- n, k, i : integer;
- s, ans : int64;
- a : array[0..2000002] of integer;
- sum, gsum : array[0..2000002] of int64;
- begin
- //assign(input, 'input.txt'); reset(input);
- //assign(output, 'output.txt'); rewrite(output);
- read(n);
- for i := 1 to 2 * n do
- read(a[i]);
- for i := 1 to 2 * n do
- sum[i] := sum[i - 1] + a[i];
- for i := 2 * n downto 1 do
- gsum[i] := gsum[i + 2] + a[i];
- ans := inf;
- for i := 2 to 2 * n do begin
- if 2 * n - i < n - 1 then
- break;
- if i = 2 then begin
- ans := min(ans, (a[1] + a[2]) * (gsum[3] + a[1]));
- continue;
- end;
- if i - 2 < n - 1 then
- s := sum[i - 1] - sum[1] + gsum[2 * i - 1]
- else
- s := sum[n] - sum[1];
- ans := min(ans, (a[1] + a[i]) * (s + a[1]));
- end;
- writeln(ans);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement