description: Monocarp plays a computer game (yet again!). This game has a unique trading mechanics.
  
  To trade with a character, Monocarp has to choose one of the items he possesses and trade it for some item the other character possesses. Each item has an integer price. If Monocarp's chosen item has price x, then he can trade it for any item (exactly one item) with price not greater than x+k.
  
  Monocarp initially has n items, the price of the i-th item he has is a_i. The character Monocarp is trading with has m items, the price of the i-th item they have is b_i. Monocarp can trade with this character as many times as he wants (possibly even zero times), each time exchanging one of his items with one of the other character's items according to the aforementioned constraints. Note that if Monocarp gets some item during an exchange, he can trade it for another item (since now the item belongs to him), and vice versa: if Monocarp trades one of his items for another item, he can get his item back by trading something for it.
  
  You have to answer q queries. Each query consists of one integer, which is the value of k, and asks you to calculate the maximum possible total cost of items Monocarp can have after some sequence of trades, assuming that he can trade an item of cost x for an item of cost not greater than x+k during each trade. Note that the queries are independent: the trades do not actually occur, Monocarp only wants to calculate the maximum total cost he can get.
  
  Input
  
  The first line contains three integers n, m and q (1 ≤ n, m, q ≤ 2 ⋅ 10^5).
  
  The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the prices of the items Monocarp has.
  
  The third line contains m integers b_1, b_2, ..., b_m (1 ≤ b_i ≤ 10^9) — the prices of the items the other character has.
  
  The fourth line contains q integers, where the i-th integer is the value of k for the i-th query (0 ≤ k ≤ 10^9).
  
  Output
  
  For each query, print one integer — the maximum possible total cost of items Monocarp can have after some sequence of trades, given the value of k from the query.
  
  Example
  
  Input
  
  
  3 4 5
  10 30 15
  12 31 14 18
  0 1 2 3 4
  
  
  Output
  
  
  55
  56
  60
  64
  64
solution: import java.util.*;
  import java.io.*;
  
  public class Main {
      public static void main(String args[]) {new Main().run();}
  
      FastReader in = new FastReader();
      PrintWriter out = new PrintWriter(System.out);
      void run() {
          work();
          out.flush();
      }
      long mod=1000000007;
      long gcd(long a,long b) {
          return a==0?b:gcd(b%a,a);
      }
      long inf=Long.MAX_VALUE/3;
      void work() {
          int n=ni(),m=ni(),q=ni();
          long[] A=na(n);
          long[] B=na(m);
          long[] D=new long[n+m];
          long[] sum=new long[n+m];
          int[] cnt=new int[n+m];
          int[] next=new int[n+m];
          int[] curPoint=new int[n+m];
          long cur=0;
          int[][] Q=new int[q][];
          long[] ret=new long[q];
          for(int i=0;i<q;i++){
              Q[i]=new int[]{ni(),i};
          }
          Arrays.sort(A);
          Arrays.sort(B);
          Arrays.sort(Q,(a1,a2)->a1[0]-a2[0]);
          for(int i=0,j=0,p=0;i<n;){
              while(j<m&&B[j]<A[i]){
                  D[p++]=B[j++];
              }
              cnt[p]++;
              curPoint[p]=p;
              D[p++]=A[i++];
              if(i==n){
                  while(j<m){
                      D[p++]=B[j++];
                  }
              }
          }
          sum[0]=D[0];
          for(int i=1;i<n+m;i++){
              sum[i]=sum[i-1]+D[i];
          }
          for(int i=m+n-1;i>=0;i--){
              if(cnt[i]>0){
                  cur+=D[i];
                  next[i]=i;
              }
          }
          PriorityQueue<int[]> pq=new PriorityQueue<>((a1,a2)->a1[0]-a2[0]);//interval,origin,curP
          for(int i=0;i<n+m-1;i++){
              if(cnt[i]>0){
                  pq.add(new int[]{(int)(D[i+1]-D[i]),i,i});
              }
          }
          for(int p=0;p<q;p++){
              int idx=Q[p][1],k=Q[p][0];
              while(pq.size()>0&&pq.peek()[0]<=k){
                  int[] node=pq.poll();
                  int origin=node[1],curP=node[2];
                  int nextP=curP+1;
                  if(cnt[nextP]>0){
                      while(next[nextP]!=nextP){
                          nextP=next[nextP];
                      }
                      cur-=sum[curPoint[nextP]]-((curPoint[nextP]-cnt[nextP])<0?0:sum[curPoint[nextP]-cnt[nextP]]);
                      cur-=sum[curP]-((curP-cnt[origin])<0?0:sum[curP-cnt[origin]]);
                      cnt[nextP]+=cnt[origin];
                      next[origin]=nextP;
                      cur+=sum[curPoint[nextP]]-((curPoint[nextP]-cnt[nextP])<0?0:sum[curPoint[nextP]-cnt[nextP]]);
                  }else{
                      curPoint[origin]=nextP;
                      cur-=sum[curP]-((curP-cnt[origin])<0?0:sum[curP-cnt[origin]]);
                      cur+=sum[nextP]-((nextP-cnt[origin])<0?0:sum[nextP-cnt[origin]]);
                      if(nextP<m+n-1)pq.add(new int[]{(int)(D[nextP+1]-D[nextP]),origin,nextP});
                  }
              }
              ret[idx]=cur;
          }
          for(long r:ret){
              out.println(r);
          }
      }
  
      @SuppressWarnings("unused")
      private ArrayList<Integer>[] ng(int n, int m) {
          ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              int s=in.nextInt()-1,e=in.nextInt()-1;
              graph[s].add(e);
              graph[e].add(s);
          }
          return graph;
      }
  
      private ArrayList<long[]>[] ngw(int n, int m) {
          ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n];
          for(int i=0;i<n;i++) {
              graph[i]=new ArrayList<>();
          }
          for(int i=1;i<=m;i++) {
              long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong();
              graph[(int)s].add(new long[] {e,w});
              graph[(int)e].add(new long[] {s,w});
          }
          return graph;
      }
  
      private int ni() {
          return in.nextInt();
      }
  
      private long nl() {
          return in.nextLong();
      }
      private double nd() {
          return in.nextDouble();
      }
      private String ns() {
          return in.next();
      }
  
      private long[] na(int n) {
          long[] A=new long[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextLong();
          }
          return A;
      }
  
      private int[] nia(int n) {
          int[] A=new int[n];
          for(int i=0;i<n;i++) {
              A[i]=in.nextInt();
          }
          return A;
      }
  }
  
  class FastReader
  {
      BufferedReader br;
      StringTokenizer st;
      InputStreamReader input;//no buffer
      public FastReader()
      {
          br=new BufferedReader(new InputStreamReader(System.in));
      }
  
      public FastReader(boolean isBuffer)
      {
          if(!isBuffer){
              input=new InputStreamReader(System.in);
          }else{
              br=new BufferedReader(new InputStreamReader(System.in));
          }
      }
  
      public boolean hasNext(){
          try{
              String s=br.readLine();
              if(s==null){
                  return  false;
              }
              st=new StringTokenizer(s);
          }catch(IOException e){
              e.printStackTrace();
          }
          return true;
      }
  
      public String next()
      {
          if(input!=null){
              try {
                  StringBuilder sb=new StringBuilder();
                  int ch=input.read();
                  while(ch=='\n'||ch=='\r'||ch==32){
                      ch=input.read();
                  }
                  while(ch!='\n'&&ch!='\r'&&ch!=32){
                      sb.append((char)ch);
                      ch=input.read();
                  }
                  return sb.toString();
              }catch (Exception e){
                  e.printStackTrace();
              }
          }
          while(st==null || !st.hasMoreElements())//回车，空行情况
          {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
  
      public int nextInt()
      {
          return (int)nextLong();
      }
  
      public long nextLong() {
          try {
              if(input!=null){
                  long ret=0;
                  int b=input.read();
                  while(b<'0'||b>'9'){
                      b=input.read();
                  }
                  while(b>='0'&&b<='9'){
                      ret=ret*10+(b-'0');
                      b=input.read();
                  }
                  return ret;
              }
          }catch (Exception e){
              e.printStackTrace();
          }
          return Long.parseLong(next());
      }
  
      public double nextDouble()
      {
          return Double.parseDouble(next());
      }
  }