Thrust: gather to different locations

I checked out the Thrust library and saw how we can use the fancy iterators to perform gather then reduce to one variable.
My problem is the following:
I have an array of data let’s say D. I also have a 2D array of maps M. I want to gather the elements of the data array to a new array R according to each line of maps.

R[i] = D[M[i][0]] + D[M[i][1]] + D[M[i][2]] …

also i don’t know each line of maps how many elements it might have for example:
R[1] = D[M[1][0]] + D[M[1][1]] + … + D[M[1][50]].
R[2] = D[M[2][0]] + D[M[2][1]] + … + D[M[2][100]].

This is also specified in an array.

I’m aware that I am going to convert them all to vectors but I would just like to know its feasibility.

Is there some easy way of gathering this data in thrust without looping through each line on the maps and reducing their data to the corresponding variable ?

Thanks in advance.