-
Asked by: bandaram_Sumanth on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.
create a structure to hold all the data values associated with each exam i.e
Si,Di,Ci and an additional data value Ni(to represent the exam number).
create an array of this stucture and store information of all the given m exams(say arr).
now sort this array in increasing order based on exam day Di.(Why? - think)
create an array of intergers to store the result.Initially all the elments of this array are 0(say res).
now iterate through the sorted array arr one by one keeping a counter initialized to 0 (cnt) and for each exam,iterate from Si to Di and
if(cnt<Ci):
if(res[i]==0):
increase cnt by 1
res[i]=Ni
else: break
now just check if value of cnt equals Ci of current exam.
if no, then petya cannot prepare for the this exam and ans is -1 , otherwise proceed to the next exam.
finally your answer is in the array res(given he can prepare for all the exams).