Given fixed incoming and outgoing amounts plus a schedule of receiving and sending days, assign each transfer to a day to maximize suppliers paid.
Medium7GreedySortingArrayNo attempts yetTime limit2sMemory limit256 MBGregory works in the accounting office of a large company. He receives money from the company's clients by wire transfer and sends money to the company's suppliers by wire transfer.
Every transfer goes through the only bank branch in the city, and that branch keeps an unusual schedule. Each day it allows exactly one kind of operation, so on some days only incoming transfers are possible and on other days only outgoing ones. Gregory can handle at most one transfer per day, and it must be the kind the branch allows that day. He chooses the other party of each transfer himself. His boss dislikes seeing him idle, so Gregory has to visit the bank every day and attempt a transfer.
Gregory must process n requests to receive money from clients and m requests to send money to suppliers. He knows the branch schedule in advance, so he sets the transfer day for every client and every supplier. The schedule has exactly n receiving days and exactly m sending days, so each request is assigned to its own day.
The account Gregory manages starts with a balance of 0. On a receiving day the amount of the client he assigned to that day is added to the balance. On a sending day he sends that amount to the supplier he assigned to that day, but if the balance is smaller than the amount, the transfer is cancelled. No money leaves the account and Gregory gets a rebuke. That supplier refuses to continue working with the company, so the payment cannot be made on a later day either.
Find an assignment that minimizes the number of suppliers Gregory fails to pay.
The first line contains the number of test cases t (1≤t≤1000).
Each test case is given in the following format. The first line contains the number of clients n and the number of suppliers m (1≤n,m≤100). The second line contains n integers ai (1≤ai≤1000), where ai is the amount the i-th client sends to Gregory's company. The third line contains m integers bj (1≤bj≤1000), where bj is the amount that must be sent to the j-th supplier. The fourth line contains a string s of length n+m consisting of n characters + and m characters -. If the k-th character of s is +, the bank allows receiving money on day k; if it is -, the bank allows sending money on day k.
For each test case, print the minimum number of suppliers Gregory does not send money to, one per line.