about summary refs log tree commit diff
path: root/codechef/nochange.lua
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-02-17 20:29:47 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-02-17 20:29:47 +0700
commit1f9cdd4cce664439625f13da1baf894190b7e9a6 (patch)
tree2d1af656692ece87c83c4f57196b5f3825d475b7 /codechef/nochange.lua
parent82e6cf7d1046d6cee16f7e8b044ec33e7ec6c4b7 (diff)
downloadcp-1f9cdd4cce664439625f13da1baf894190b7e9a6.tar.gz
Thank you Corona for giving me some time to do this
Diffstat (limited to 'codechef/nochange.lua')
-rwxr-xr-xcodechef/nochange.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/codechef/nochange.lua b/codechef/nochange.lua
new file mode 100755
index 0000000..818959c
--- /dev/null
+++ b/codechef/nochange.lua
@@ -0,0 +1,36 @@
+#!/usr/bin/env lua
+local read = io.read
+local print = print
+local table = {concat = table.concat, insert = table.insert}
+
+for t = 1, read('*n') do
+  local n, p = read('*n', '*n')
+  local d = {}
+  for i = 1, n do table.insert(d, read('*n')) end
+
+  local unanswered, previous = true, 1
+  for k, v in ipairs(d) do
+    if p % v ~= 0 then
+      local c = {}
+      for i = 1, k-1 do table.insert(c, 0) end
+      table.insert(c, p//v+1)
+      for i = k+1, n do table.insert(c, 0) end
+      print(('YES %s'):format(table.concat(c, ' ')))
+      unanswered = false
+      break
+    end
+
+    if v % previous ~= 0 then
+      local c = {}
+      for i = 1, k-2 do table.insert(c, 0) end
+      table.insert(c, v//previous+1)
+      table.insert(c, p//v-1)
+      for i = k+1, n do table.insert(c, 0) end
+      print(('YES %s'):format(table.concat(c, ' ')))
+      unanswered = false
+      break
+    end
+    previous = v
+  end
+  if unanswered then print('NO') end
+end