Problem description have a machine, and give you this machine's worksheet, there are n tasks on the worksheet, the machine in TI time to perform the first task, 1 seconds to complete 1 tasks. There are M queries, each of which has a number Q, which indicates if there is a task request outside of a worksheet at q time, calculate when this task can be executed. The machine always executes according to the worksheet and executes requests for tasks outside the worksheet as soon as the machine is idle.
The first line of input inputs contains an integer t, which indicates a total of T-Group test data.
For each set of test data: The first line is two digits n, m, indicating that there are n tasks in the worksheet, there are M queries, and the second line is n different numbers t1, T2, t3....tn, which indicates that the machine performs the I task at ti time. Next M-line, each row has a number Q, which indicates that there is a task request outside the worksheet at q time.
Special reminder: M-inquiries are irrelevant to each other.
[Technical specification]1. T <= 50 2. 1 <= N, M <= 10^5 3. 1 <= ti <= 2*10^5, 1 <= i <= n 4. 1 <= q <= 2*10^5
Output for each query, calculate and output when the task can be executed, one row for each query.
Sample Input15 51 2 3 5 612345
Sample Output44447
Initialize with recursion to find the complexity of the time to O (1).
1#include <cstdio>2#include <cstring>3 using namespacestd;4 intv[200005],ans[200005],n;5 intDfsintx)6 {7 if(x==2*n+2)return 0;8 if(!v[x]) {DFS (x+1);returnans[x]=x;}9 returnAns[x]=dfs (x+1);Ten } One intMain () A { - intT,m,p,i,a; -scanf"%d",&t); the while(t--) - { -memset (V,0,sizeof(v)); -scanf"%d%d",&n,&m); + for(i=1; i<=n;i++) - { +scanf"%d",&a); Av[a]=1; at } -Dfs1); - while(m--) - { -scanf"%d",&p); -printf"%d\n", Ans[p]); in } - } to}
HDU 4907 Task Schedule (Recursive)