about summary refs log tree commit diff
path: root/2ndary/12/TP-HN-2015/bai2.pas
diff options
context:
space:
mode:
Diffstat (limited to '2ndary/12/TP-HN-2015/bai2.pas')
-rw-r--r--2ndary/12/TP-HN-2015/bai2.pas54
1 files changed, 54 insertions, 0 deletions
diff --git a/2ndary/12/TP-HN-2015/bai2.pas b/2ndary/12/TP-HN-2015/bai2.pas
new file mode 100644
index 0000000..858d2b1
--- /dev/null
+++ b/2ndary/12/TP-HN-2015/bai2.pas
@@ -0,0 +1,54 @@
+var
+  n, m, i, b, c, j: word;
+  a: array of word;
+  f: text;
+  bc: array[1..1000, 1..1000] of boolean;
+  bestprice: array[1..1000] of word;
+  v: longint = 0;
+
+
+begin
+  assign(f, 'BAI2.INP');
+  reset(f);
+
+  read(f, n);
+  setlength(a, n);
+  for i := 0 to n - 1 do
+    read(f, a[i]);
+
+  fillchar(bc, sizeof(bc), false);
+  readln(f, m);
+  for i := 1 to m do
+    begin
+      read(f, b, c);
+      bc[b][c] := true
+    end;
+
+  close(f);
+
+  for i := 1 to 1000 do
+    bc[i][1000] := true;
+
+  for i := 1 to 1000 do
+    if bc[1000][i] then
+      begin
+        bestprice[1000] := i;
+        break
+      end;
+
+  for i := 999 downto 1 do
+    begin
+      for j := 1 to bestprice[i + 1] do
+        if bc[i][j] then
+          break;
+      bestprice[i] := j
+    end;
+
+  for i := 0 to n - 1 do
+    inc(v, bestprice[a[i]]);
+
+  assign(f, 'BAI2.OUT');
+  rewrite(f);
+  writeln(f, v);
+  close(f)
+end.