about summary refs log tree commit diff
path: root/12/TP-HN-2015/bai2.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-09 21:39:26 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2016-11-09 23:10:54 +0700
commit10de10a507238f3be43dee304e057679b5bb2736 (patch)
tree748d8f04dda4aa9ae2b71ade67eb8a0dd543e262 /12/TP-HN-2015/bai2.pas
parent94f49ef11037832a173d268ca932fe34cf78b472 (diff)
downloadcp-10de10a507238f3be43dee304e057679b5bb2736.tar.gz
Thêm đề TP 12 năm 2015-2016
Diffstat (limited to '12/TP-HN-2015/bai2.pas')
-rw-r--r--12/TP-HN-2015/bai2.pas54
1 files changed, 54 insertions, 0 deletions
diff --git a/12/TP-HN-2015/bai2.pas b/12/TP-HN-2015/bai2.pas
new file mode 100644
index 0000000..858d2b1
--- /dev/null
+++ b/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.