NOCHANGE greedy?

I just want to know if this is a greedy one
my AC code
My algorithm was simple
let ans[0..n-1]={0} be the multiset
for i from n-1 to 0 {
if Di divides p {
ans[i] = p floordiv Di - 1
p -= Di * ans[i]
} else
ans[i] = 1 + p floordiv Di
}
if p > 0 and i==-1 then no multiset exists