about summary refs log tree commit diff
path: root/codechef/nochange.lua
blob: 818959ca2f608911da84b21dd817e9290d772d7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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