Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  test
Language: C/C++
Code:


flist = [int(h) for h in input().split()]
n = flist[0]
x = flist[1]
k = 0
SUM = 0
firstdigit = []
state = []
total = []
if x > 1000000000 or x < 1:
    print("ERROR")
else:
    if n > 200000 or n < 1:
            #print("ERROR")
            print("NO")
    else:
        list=[] 
        for i in range(0,n): 
            list.append([int(j) for j in input().split()])
            SUM = SUM + list[i][0]
            total.append(str(list[i][0]))
            if list[i][0] > x or list[i][0] < 0:
                print("NO") 
                break
            if list[i][1] > x or list[i][1] < 0:
                print("NO")
                break
            else:
                firstdigit.append(list[i][0]) 
                state.append(list[i][1] - list[i][0])
            
   
        

        
        g = 0
        while g < n and SUM < x:
            W = x - SUM
            if W < state[g]:
                firstdigit[g] = firstdigit[g] + W
                total[g] = str(firstdigit[g])
                SUM = x
            else:     
                firstdigit[g] = firstdigit[g] + state[g]
                total[g] = str(firstdigit[g])
                SUM = SUM + state[g]
            g = g+1


if SUM == x:
    print("YES\n", ' '.join(total))
 
else:
    print("NO")

        




Comments: