scoring-in-exam-1
Source: hackerearth
Difficulty: EASY

Milly is at the examination hall where she is reading a question paper. She checked the question paper and discovered that there are N questions in that paper. Each question has some score value. Ideally it's like questions requiring more time have more score value and strangely no two questions on the paper require same time to be solved.

She is very excited by looking these questions. She decided to solve K questions while maximizing their score value. Could you please help Milly to determine the exact time she needs to solve the questions.

Input
First line of input contains two space separated integers N and Q, where N is the number of questions available and Q is number of queries
 Next line contains N space separated integers denoting the time Ti of N questions
 Next line contains N space separated integers denoting the scores Si of N questions
 Next Q lines contains a number K each, the number of questions she wants to solve

Output

Print the time required for each query in a separate line.

Constraints
1 ≤ N ≤ 10^5 
1 ≤ Q ≤ 10^5 
1 ≤ K ≤ N 
1 ≤ Ti, Si ≤ 10^9 

SAMPLE INPUT
5 2
2 3 9 4 5
3 5 11 6 7
5
3

SAMPLE OUTPUT
23
18

Explanation

For second query k = 3,
Three most scoring questions are those with values 11, 7 and 6 and time required are 9, 5 and 4 respectively so the total total time  required = 18.


import numpy as np

def main():
	N,Q=list(map(int,input().split(" ")))
	score_time=sorted(map(lambda a, b: (b,a) , list(map(int,input().split(" "))), list(map(int,input().split(" ")))))
	score_time=score_time[::-1]
	added_time = np.cumsum([i[1] for i in score_time])
	for i in range(Q):
		K=int(input())
		print(added_time[K-1])



main()
																																																																																																																														


def find_max(n):
	ll = len(mp)
	if n >= ll:
	    for j in range(ll-1,n):
	    	mp.append(ss[j][0]+mp[-1])
	return mp[n]


mp = [0]
n,q= list(map(int,input().split(' ')))
t = list(map(int,input().split(' ')))
m = list(map(int,input().split(' ')))
ss = sorted(zip(t,m), reverse=1, key=lambda x:x[1])
#print ss
for i in range(q):
	no = eval(input())
	if no:
		print(find_max(no))
	else:
		print(0)


str=input()
N,Q=[int(x) for x in str.split()]
time=input()
TList=[int(t) for t in time.split()[:N+1]]
score=input()
SList=[int(s) for s in score.split()[:N+1]]
sortedTuple=sorted(zip(TList,SList),key=lambda tup:tup[1],reverse=True)

sumList=[]
sumList.append(sortedTuple[0][0])
for i in range(1,len(sortedTuple)):
	sumList.append(sumList[i-1]+sortedTuple[i][0])

for x in range(0,Q):
	query=int(input())
	print(sumList[query-1])



import sys


def readoneline():
	linenostrip=sys.stdin.readline()
	linestrip=linenostrip.strip()
	lst=linestrip.split(" ")
	return lst


nqlist = readoneline()
n=int(nqlist[0])
q=int(nqlist[1])


tlist = readoneline()
slist = readoneline()


unsortedlist = []
for i in range(0,n):
	ti=int(tlist[i])
	si=int(slist[i])
	unsortedlist.append((si, ti))

sortedlist = sorted(unsortedlist, key=lambda x: x[0])
srevlist = list(reversed(sortedlist))

prefixsumlist = []

psum=0
for tup in srevlist:
	psum = psum + tup[1]
	prefixsumlist.append(psum)


for i in range(0,q):
	klist = readoneline()
	k = int(klist[0])
	print(prefixsumlist[k-1])


n,q = list(map(int,input().split()))
t = list(map(int,input().split()))
s = list(map(int,input().split()))
qw = [x for (y,x) in sorted(zip(s,t))]
qw.reverse()
for i in range(1,n):
	qw[i] = qw[i]+qw[i-1]
for i in range(q):
	j = eval(input())
	print(qw[j-1])


n,q=input().split()
n=int(n)
q=int(q)
time=list(map(int,input().split()))
marks=list(map(int,input().split()))
time.sort(reverse=True)
for i in range(1,len(time)):
	time[i]=time[i-1]+time[i]
	
for i in range(q):
	k=int(input())
	print(time[k-1])


N, Q = [int(x) for x in input().strip().split()]
arr1 = [int(x) for x in input().strip().split()]
arr2 = [int(x) for x in input().strip().split()]

def qsort(inlist):
	if inlist == []: 
		return []
	else:
		pivot = inlist[0]
		lesser = qsort([x for x in inlist[1:] if x < pivot])
		greater = qsort([x for x in inlist[1:] if x >= pivot])
		return lesser + [pivot] + greater

my_map = {}
for i in range(N):
	my_map[arr2[i]] = arr1[i]
del arr1
arr2.sort()
arr3 = []
sol_map = {}
summer = 0
for j in range(N - 1 , -1, -1):
	summer += my_map[arr2[j]]
	sol_map[N - j] = summer
	
for i in range(Q):
	print(sol_map[eval(input())])



N, Q = [int(x) for x in input().strip().split()]
arr1 = [int(x) for x in input().strip().split()]
arr2 = [int(x) for x in input().strip().split()]

my_map = {}
for i in range(N):
	my_map[arr2[i]] = arr1[i]
del arr1
arr2.sort()
arr3 = []
sol_map = {}
summer = 0
for j in range(N - 1 , -1, -1):
	summer += my_map[arr2[j]]
	sol_map[N - j] = summer
	
for i in range(Q):
	print(sol_map[eval(input())])



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
[N,Q] = [int(x) for x in input().split()]
T=[int(x) for x in input().split()]
l={}
for i,x in enumerate(input().split()):
	if int(x) in l:
		l[int(x)].append(T[i])
	else:
		l[int(x)]=[T[i]]
#print l
#for i,x in enumerate(S):
#	l[x]=T[i]
z=list(sorted(list(l.keys()),reverse=True))
#print len(z)
a=[0]
for j in range(len(l)):
	for c in l[z[j]]:
		a.append(a[-1]+int(c))
for u in range(Q):
	t=int(input())
	print(a[t])


no_of_q, q_no = list(map(int,input().split()))
time = list(map(int,input().split()))
marks = list(map(int,input().split()))
mapped = sorted(zip(time,marks), reverse=1,key=lambda a:a[1])
max_times = []
#print mapped
def get_time_for_max_marks(no_of_questions):
	curr_len = len(max_times)
	if no_of_questions >= curr_len:
		for i in range(curr_len,no_of_questions):
			if max_times:
				max_times.append(max_times[-1]+mapped[i][0])
			else:
				max_times.append(mapped[0][0])
	return max_times[no_of_questions-1]


for j in range(q_no):
	querry = eval(input())
	print(get_time_for_max_marks(querry))


def find_max(n):
	ll = len(mp)
	if n >= ll:
	    for j in range(ll-1,n):
	    	mp.append(ss[j][0]+mp[-1])
	return mp[n]


mp = [0]
n,q= list(map(int,input().split(' ')))
t = list(map(int,input().split(' ')))
m = list(map(int,input().split(' ')))
ss = sorted(zip(t,m), reverse=1, key=lambda x:x[1])
#print ss
for i in range(q):
	no = eval(input())
	if no:
		print(find_max(no))
	else:
		print(0)


import numpy as np

def main():
	N,Q=list(map(int,input().split(" ")))
	score_time=sorted(map(lambda a, b: (b,a) , list(map(int,input().split(" "))), list(map(int,input().split(" ")))))
	score_time=score_time[::-1]
	added_time = np.cumsum([i[1] for i in score_time])
	for i in range(Q):
		K=int(input())
		print(added_time[K-1])



main()
																																																																																																																														


def find_max(n):
	ll = len(mp)
	if n >= ll:
	    for j in range(ll-1,n):
	    	mp.append(ss[j][0]+mp[-1])
	return mp[n]


mp = [0]
n,q= list(map(int,input().split(' ')))
t = list(map(int,input().split(' ')))
m = list(map(int,input().split(' ')))
ss = sorted(zip(t,m), reverse=1, key=lambda x:x[1])
#print ss
for i in range(q):
	no = eval(input())
	if no:
		print(find_max(no))
	else:
		print(0)


n , q = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
t.sort(reverse=True)
s.sort(reverse=True)
query = []
sum = []
for i in range(q):
	query.append(int(input()))
for k in query:
	#if sum[k-1] != 0:
	if len(sum) >= k:
		print(sum[k-1])
		continue
	for i in range(len(sum),k):
		if i == 0:
			p = t[i]
		else:
			p = sum[i-1]+t[i]
		sum.append(p)
	print(sum[k-1])
	
	


n,q = list(map(int , input().split()))
l = []
time = list ( map ( int , input().split()))
score = list (map ( int , input().split()))
s = 0
for i in range (n):
	tmp = []
	tmp.append(time[i])
	s+=time[i]
	tmp.append(score[i])
	l.append(tmp)

l.sort()
a = []
a.append(s)
for i in range(n):
	s-=l[i][0]
	a.append(s)

for i in range(q):
	k = int (input())
	print(a[n - k])




import heapq
N,Q = list(map(int,input().split()))
T = list(map(int,input().split()))
S = list(map(int,input().split()))
C = list(zip([-1*i for i in S],T))
C.sort()
#precompute ans
ans = [-1]*N
ans[0] = C[0][1]
for index in range(1,N) :
	ans[index] = ans[index-1] + C[index][1]

for _ in  range(Q) :
	K = int(input().strip())
	print(ans[K-1])



nos, queries = input().split(" ")
nos, queries = int(nos), int(queries)

timesOfQuestions = input().split(" ")
marksOfQuestions = input().split(" ")

itimesOfQuestions = []
imarksOfQuestions = []

marksToTimeMapping = {}

for time in timesOfQuestions:
	itimesOfQuestions.append(int(time))
	
count = 0

for mark in marksOfQuestions:
	imarksOfQuestions.append(int(mark))
	marksToTimeMapping[int(mark)] = itimesOfQuestions[count]
	count += 1
	
sortedMarks = reversed(sorted(imarksOfQuestions))

sumOfTimes = []
sum1 = 0

for sm in sortedMarks:
	sum1 += marksToTimeMapping[sm]
	sumOfTimes.append(sum1)
	
for q in range(1,queries + 1):
	query = int(input())
	print(sumOfTimes[query- 1])
	

	



# your code goes here

n,q = list(map(int,input().split()))
time = list(map(int,input().split()))
score = list(map(int,input().split()))
time.sort(reverse=True)
sum1 = [0]*len(time)
sum1[0] = time[0]
for i in range(1,len(time)):
	sum1[i] = time[i] + sum1[i-1]
	
for i in range(q):
	query = eval(input())
	print(sum1[query-1],end='\n')


N, Q = list(map(int, input().split()))
T = list(map(int, input().split()))
S = list(map(int, input().split()))
tup = [(S[counter], t) for counter, t in enumerate(T)]
s_tup = sorted(tup, key=lambda tp: tp[0], reverse=True)
sum_val = [ 0 for i in range(N)]
sum_val [0] = s_tup[0][1]
for i in range(1, N):
	sum_val[i] += sum_val[i-1] + s_tup[i][1]
for i in range(Q):
	n = int(input())
	print(sum_val[n-1])


n,q=list(map(int, input().split()))
t = list(map(int, input().split()))
s = list(map(int, input().split()))
l = []
for i in range(n):
	l.append((s[i],t[i]))
l.sort(reverse=True)
SUMI=[0]*(n+1)
for i in range(n):
	SUMI[i+1] = SUMI[i]+l[i][1]
for qi in range(q):
	k = eval(input())
	print(SUMI[k])
	


nos, queries = input().split(" ")
nos, queries = int(nos), int(queries)

timesOfQuestions = input().split(" ")
marksOfQuestions = input().split(" ")

itimesOfQuestions = []
imarksOfQuestions = []

marksToTimeMapping = {}

for time in timesOfQuestions:
	itimesOfQuestions.append(int(time))
	
count = 0

for mark in marksOfQuestions:
	imarksOfQuestions.append(int(mark))
	marksToTimeMapping[int(mark)] = itimesOfQuestions[count]
	count += 1
	
sortedMarks = reversed(sorted(imarksOfQuestions))

sumOfTimes = []
sum1 = 0

for sm in sortedMarks:
	sum1 += marksToTimeMapping[sm]
	sumOfTimes.append(sum1)
	
for q in range(1,queries + 1):
	query = int(input())
	print(sumOfTimes[query- 1])
	

	



import sys

def getItem(x):
	return x[0]
	
n,q=list(map(int, sys.stdin.readline().split(" ")))
t=list(map(int, sys.stdin.readline().split(" ")))
s=list(map(int, sys.stdin.readline().split(" ")))
a=[]
for i in range(0,n):
	a.append((s[i],t[i]))

a=sorted(a,key=getItem,reverse=True)
res=[0]*n
res[0]=a[0][1]
for i in range(1,n):
	res[i]=res[i-1]+a[i][1]
while(q>0):
	k=int(input())
	print(res[k-1])
	q-=1



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import collections
n,q = input().strip().split(' ')
n,q = [int(n),int(q)]

T = input().strip().split(' ')
T = [int(i) for i in T]

S = input().strip().split(' ')
S = [int(i) for i in S]


D ={}
for it in range(0,n):
	D[int(S[it])] = int(T[it])

S.sort()
S.reverse()
ans =[]

ans.append(D[S[0]])

for qu in range(1,n):
	ans.append(ans[qu-1]+D[S[qu]])
	
for qu in range(0,q):
	k = eval(input());
	print(ans[k-1])

	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'

N,Q=list(map(int,input().split()))
Time=list(map(int,input().split()))
T=sorted(Time,reverse=True)
Scores=list(map(int,input().split()))
l=list()
le=len(T)
s=0
for i in range(le):
	s=s+T[i]
	l.append(s)

for _ in range(Q):
	q=int(input())
	print(l[q-1])
	
	


inStr = input()
[N, Q] = [int(x) for x in inStr.split(" ")]
inStr = input()
T = [int(x) for x in inStr.split(" ")]
inStr = input()
S = [int(x) for x in inStr.split(" ")]

T.sort()
T.reverse()

query = []
for i in range(Q):
	query.append(eval(input()))

Tsum = []
temp = 0
for t in T:
	temp = temp + t
	Tsum.append(temp)

for q in query:
	print(Tsum[q-1])


import sys
n,q=list(map(int,input().split()))
time=list(map(int,input().split()))
scr=list(map(int,input().split()))
l=[]
for i in range(0,n):
	l.append([scr[i],time[i]])
l.sort(reverse=True)
d={}
sc=0
for i in range(0,n):
	sc=sc+l[i][1]
	d[i+1]=sc

while q>0:
	print(d[eval(input())])
	q=q-1



n,q=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a.sort()
c=[0]
i=0
while n>0:
	i=i+a[n-1]
	c.append(i)
	n=n-1
for _ in range(q):
	k=eval(input())
	print(c[k])


n, q = tuple(list(map(int, input().strip().split(' '))),)
t = list(map(int, input().strip().split()))
s = list(map(int, input().strip().split()))

temp = []
#print temp
#print temp
i = 0
for _ in t:
	temp.append((((s[i], t[i]))))
	i += 1
temp.sort(reverse=True)

#print "sorted = ", temp
#print "nlargest = ", nlargest(3, temp)
i = 1
maxtime = [0]*(n+1)
while (i < (n + 1)):
	maxtime[i] = maxtime[i-1] + temp[i-1][1]
	i += 1
"""
	j = 0
	timev = 0
	while j < i:
		timev += temp[j][1]
		j += 1
	print i
	maxtime[i] = timev
	i += 1
"""
i = 0
while (i < q):
	queries = int(input().strip())
	print(maxtime[queries])
	i += 1


n, q = tuple(list(map(int, input().strip().split(' '))),)
t = list(map(int, input().strip().split()))
s = list(map(int, input().strip().split()))

temp = []
#print temp
#print temp
i = 0
for _ in t:
	temp.insert(0, (((s[i], t[i]))))
	i += 1
temp.sort(reverse=True)

#print "sorted = ", temp
#print "nlargest = ", nlargest(3, temp)
i = 1
maxtime = [0]*(n+1)
while (i < (n + 1)):
	maxtime[i] = maxtime[i-1] + temp[i-1][1]
	i += 1
"""
	j = 0
	timev = 0
	while j < i:
		timev += temp[j][1]
		j += 1
	print i
	maxtime[i] = timev
	i += 1
"""
i = 0
while (i < q):
	queries = int(input().strip())
	print(maxtime[queries])
	i += 1


def main():
	info=list(map(int,input().split()))
	n=info[0]
	m=info[1]
	ar=list(map(int,input().split()))
	arr=list(map(int,input().split()))
	arr, ar= list(zip(*sorted(zip(arr, ar))))
	s=[0]*n
	s[0]=ar[n-1]
	l=n-1
	i=1
	while(l>=1):
		s[i]=s[i-1]+ar[l-1]
		l-=1
		i+=1
	i=0
	while(i<m):
		k=int(input())
		print(s[k-1])
		i+=1
		
main()


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import collections
n,q = input().strip().split(' ')
n,q = [int(n),int(q)]

T = input().strip().split(' ')
T = [int(i) for i in T]

S = input().strip().split(' ')
S = [int(i) for i in S]


D ={}
for it in range(0,n):
	D[int(S[it])] = int(T[it])

S.sort()
S.reverse()
ans =[]

ans.append(D[S[0]])

for qu in range(1,n):
	ans.append(ans[qu-1]+D[S[qu]])
	
for qu in range(0,q):
	k = eval(input());
	print(ans[k-1])

	


import os 
import sys

def conv(s) :
	return int(s)

l = input()
l = l.split()
n = int(l[0])
q = int(l[1])
t = input()
t = list(map(conv,t.split()))
c = input()
t.sort(reverse=True)
s = []
for x in range(len(t)) :
	if x > 0 :
		s.append(s[x-1]+t[x])
	else :
		s.append(t[x])

for x in range(q) :
	k = int(input())
	print(s[k-1])