about summary refs log tree commit diff
path: root/others/other/diffsum.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-12 21:35:03 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-13 11:37:17 +0700
commit1fca99158c60a94497b21ff527d4071d96c9c0f1 (patch)
tree3b6533c4c5fa4f67a6ae0fffdf042f4b46a749e6 /others/other/diffsum.pas
parent7c9b47ab9149d292d5493c865dfb8742a7450472 (diff)
downloadcp-1fca99158c60a94497b21ff527d4071d96c9c0f1.tar.gz
others/other: Add diffsum.{py,pas} and lseq.c
Diffstat (limited to 'others/other/diffsum.pas')
-rw-r--r--others/other/diffsum.pas42
1 files changed, 42 insertions, 0 deletions
diff --git a/others/other/diffsum.pas b/others/other/diffsum.pas
new file mode 100644
index 0000000..e37152c
--- /dev/null
+++ b/others/other/diffsum.pas
@@ -0,0 +1,42 @@
+var
+  f: text;
+  n, i, tmp: smallint;
+  a: array of smallint;
+
+begin
+  assign(f, 'DIFFSUM.INP');
+  reset(f);
+  read(f, n);
+  close(f);
+
+  if n > 1 then
+    setlength(a, trunc(sqrt(n * 2 + 2.25) - 1.5))
+  else
+    setlength(a, 1);
+  tmp := 0;
+  for i := 0 to length(a) - 2 do
+    begin
+      a[i] := i + 2;
+      inc(tmp, a[i])
+    end;
+  a[length(a) - 1] := n - tmp;
+
+  if length(a) > 1 then
+    while a[length(a) - 1] - a[length(a) - 2] > 2 do
+      for i := length(a) - 1 downto 1 do
+        begin
+          tmp := (a[i] - 1 - a[i - 1]) div 2;
+          if tmp > 0 then
+            begin
+              dec(a[i], tmp);
+              inc(a[i - 1], tmp)
+            end
+        end;
+
+  assign(f, 'DIFFSUM.OUT');
+  rewrite(f);
+  for i in a do
+    write(f, i, ' ');
+  writeln(f);
+  close(f)
+end.