description: Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of n heroes, the strength of the i-th hero is equal to a_i.
  
  According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon's defense is equal to x, then you have to send a hero with a strength of at least x to kill it. If the dragon's attack power is y, then the total strength of the heroes defending the castle should be at least y.
  
  The player can increase the strength of any hero by 1 for one gold coin. This operation can be done any number of times.
  
  There are m dragons in the game, the i-th of them has defense equal to x_i and attack power equal to y_i. Petya was wondering what is the minimum number of coins he needs to spend to defeat the i-th dragon.
  
  Note that the task is solved independently for each dragon (improvements are not saved).
  
  Input
  
  The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — number of heroes.
  
  The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^{12}), where a_i is the strength of the i-th hero.
  
  The third line contains a single integer m (1 ≤ m ≤ 2 ⋅ 10^5) — the number of dragons.
  
  The next m lines contain two integers each, x_i and y_i (1 ≤ x_i ≤ 10^{12}; 1 ≤ y_i ≤ 10^{18}) — defense and attack power of the i-th dragon.
  
  Output
  
  Print m lines, i-th of which contains a single integer — the minimum number of coins that should be spent to defeat the i-th dragon.
  
  Example
  
  Input
  
  
  4
  3 6 2 3
  5
  3 12
  7 9
  4 14
  1 10
  8 7
  
  
  Output
  
  
  1
  2
  4
  0
  2
  
  Note
  
  To defeat the first dragon, you can increase the strength of the third hero by 1, then the strength of the heroes will be equal to [3, 6, 3, 3]. To kill the dragon, you can choose the first hero.
  
  To defeat the second dragon, you can increase the forces of the second and third heroes by 1, then the strength of the heroes will be equal to [3, 7, 3, 3]. To kill the dragon, you can choose a second hero.
  
  To defeat the third dragon, you can increase the strength of all the heroes by 1, then the strength of the heroes will be equal to [4, 7, 3, 4]. To kill the dragon, you can choose a fourth hero.
  
  To defeat the fourth dragon, you don't need to improve the heroes and choose a third hero to kill the dragon.
  
  To defeat the fifth dragon, you can increase the strength of the second hero by 2, then the strength of the heroes will be equal to [3, 8, 2, 3]. To kill the dragon, you can choose a second hero.
solution: 							/*
  							ID: abdelra29
  		LANG: JAVA
  		PROG: zerosum
  							*/
  								/*
  								TO LEARN
  						
  								2-euler tour
  							
  								*/
  								/*
  								TO SOLVE 
  								*/
  								/*
  								bit manipulation shit
  								1-Computer Systems: A Programmer's Perspective
  								2-hacker's delight
  								*/
  								/*
  								TO WATCH
  								
  								*/
  								            import java.util.*;
  										    import java.math.*;
  										    import java.io.*; 
  										    import java.text.DecimalFormat;
  										    import java.util.stream.Collectors;
  
  
  										       public class A{
  								            static FastScanner scan=new FastScanner();
  											     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  
  				public static void main(String[] args)  throws Exception 
  								      {
  								 /*
  								 very important tips 
  								 1-just fucking think backwards once in your shitty life
  								 2-consider brute forcing and finding some patterns and observations
  								 3-when you're in contest don't get out because you think there is no enough time
  								 4-don't get stuck on one approach 
  								 */
  							   
  				//scan=new FastScanner("evaluations.in");
  				//out = new PrintWriter("sabotage.out");
  
  							
  										 							 /*
  										 READING 
  								
  										 3-Introduction to DP with Bit-masking codeforces
  										 4-Bit Manipulation hacker-earth
  										 5-read more about mobious and inclusion-exclusion 
  					 				     6-read more about Fermat little theorem
  										 */
  										 /*
  										
  										 */
  										 
  
  					 			
  										      
  	int tt=1;
  			//					tt=scan.nextInt();
                                   int T=1;
  
  									 outer:while(tt-->0)
  									    {
  									    int n=scan.nextInt();
  									    long arr[]=new long[n];
  									    TreeSet<Long>set=new TreeSet<Long>();
  									    long sum=0;
  									    for(int i=0;i<n;i++){
  									    	arr[i]=scan.nextLong();
  									    	sum+=arr[i];
  									    	set.add(arr[i]);
  									    }
  									    int m=scan.nextInt();
  									    //long x[]=new long[n];
  									    for(int i=0;i<m;i++)
  									    {
  									    	long x=scan.nextLong(),y=scan.nextLong();
  									    long res=Long.MAX_VALUE,res2=Long.MAX_VALUE;
  									    	Long hi=set.higher(x-1);
  									    	if(hi!=null)
  									    	{
  									    		res=Math.max(0,y-(sum-hi));
  									    	}
  									    	Long lo=set.lower(x+1);
  									    	if(lo!=null)
  									    	{
  									    		res2=Math.max(x-lo,0);
  									    		long rem=Math.max(0,y-(sum-lo));
  									    		res2+=rem;
  									    	}
  									    	out.println(Math.min(res,res2));
  
  									    }
  
  									    
  
  		 }							
  		
  	        
  
  				out.close();
  							}
  							
  							
  
  							static class special implements Comparable<special>{
  							int cnt,idx;
  							String s;
  							public special(int cnt,int idx,String s)
  							{
  								this.cnt=cnt;
  								this.idx=idx;
  								this.s=s;
  							}
  
  								 @Override
  										            public int hashCode() {
  										                return (int)42;
  										            }
  								  @Override
  										            public boolean equals(Object o){
  										            //	System.out.println("FUCK");
  										                if (o == this) return true;
  										                if (o.getClass() != getClass()) return false;
  										                special t = (special)o;
  										                return t.cnt == cnt && t.idx == idx;
  										            }
  										            public int compareTo(special o1)
  										            {
  										            	if(o1.cnt==cnt)
  										            	{
  										            		return o1.idx-idx;
  										            	}
  										            	return o1.cnt-cnt;
  										            }
  							}
  				
  										   
  										     static long binexp(long a,long n)
  										    {
  										        if(n==0)
  										            return 1;
  										        long res=binexp(a,n/2);
  										        if(n%2==1)
  										            return res*res*a;
  										        else 
  										            return res*res;
  										    }
  										     
  										    static long powMod(long base, long exp, long mod) {
  										           if (base == 0 || base == 1) return base;
  										           if (exp == 0) return 1;
  										           if (exp == 1) return (base % mod+mod)%mod;
  										           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
  										           R *= R;
  										           R %= mod;
  										           if ((exp & 1) == 1) {
  										               return (base * R % mod+mod)%mod;
  										           }
  										           else return (R %mod+mod)%mod;
  										       }
  										    static double dis(double x1,double y1,double x2,double y2)
  										    {
  										        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  										    }
  										    static long mod(long x,long y)
  										        {
  										            if(x<0)
  										                x=x+(-x/y+1)*y;
  										            return x%y;
  										        }
  										     public static  long pow(long b, long e) {
  										                long r = 1;
  										                while (e > 0) {
  										                    if (e % 2 == 1) r = r * b ;
  										                    b = b * b;
  										                    e >>= 1;
  										                }
  										                return r;
  										            }
  										    private static void sort(int[] arr) {
  										            List<Integer> list = new ArrayList<>();
  										            for (int object : arr) list.add(object);
  										            Collections.sort(list);
  										        //Collections.reverse(list);
  										            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  										        }
  										    private static void sort2(long[] arr) {
  										            List<Long> list = new ArrayList<>();
  										            for (Long object : arr) list.add(object);
  										            Collections.sort(list);
  										        Collections.reverse(list);
  										            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  										        }
  										     static class FastScanner
  								{
  								    private int BS = 1 << 16;
  								    private char NC = (char) 0;
  								    private byte[] buf = new byte[BS];
  								    private int bId = 0, size = 0;
  								    private char c = NC;
  								    private double cnt = 1;
  								    private BufferedInputStream in;
  								 
  								    public FastScanner() {
  								        in = new BufferedInputStream(System.in, BS);
  								    }
  								 
  								    public FastScanner(String s) {
  								        try {
  								            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  								        } catch (Exception e) {
  								            in = new BufferedInputStream(System.in, BS);
  								        }
  								    }
  								 
  								    private char getChar() {
  								        while (bId == size) {
  								            try {
  								                size = in.read(buf);
  								            } catch (Exception e) {
  								                return NC;
  								            }
  								            if (size == -1) return NC;
  								            bId = 0;
  								        }
  								        return (char) buf[bId++];
  								    }
  								 
  								    public int nextInt() {
  								        return (int) nextLong();
  								    }
  								 
  								    public int[] nextInts(int N) {
  								        int[] res = new int[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = (int) nextLong();
  								        }
  								        return res;
  								    }
  								 
  								    public long[] nextLongs(int N) {
  								        long[] res = new long[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = nextLong();
  								        }
  								        return res;
  								    }
  								 
  								    public long nextLong() {
  								        cnt = 1;
  								        boolean neg = false;
  								        if (c == NC) c = getChar();
  								        for (; (c < '0' || c > '9'); c = getChar()) {
  								            if (c == '-') neg = true;
  								        }
  								        long res = 0;
  								        for (; c >= '0' && c <= '9'; c = getChar()) {
  								            res = (res << 3) + (res << 1) + c - '0';
  								            cnt *= 10;
  								        }
  								        return neg ? -res : res;
  								    }
  								 
  								    public double nextDouble() {
  								        double cur = nextLong();
  								        return c != '.' ? cur : cur + nextLong() / cnt;
  								    }
  								 
  								    public double[] nextDoubles(int N) {
  								        double[] res = new double[N];
  								        for (int i = 0; i < N; i++) {
  								            res[i] = nextDouble();
  								        }
  								        return res;
  								    }
  								 
  								    public String next() {
  								        StringBuilder res = new StringBuilder();
  								        while (c <= 32) c = getChar();
  								        while (c > 32) {
  								            res.append(c);
  								            c = getChar();
  								        }
  								        return res.toString();
  								    }
  								 
  								    public String nextLine() {
  								        StringBuilder res = new StringBuilder();
  								        while (c <= 32) c = getChar();
  								        while (c != '\n') {
  								            res.append(c);
  								            c = getChar();
  								        }
  								        return res.toString();
  								    }
  								 
  								    public boolean hasNext() {
  								        if (c > 32) return true;
  								        while (true) {
  								            c = getChar();
  								            if (c == NC) return false;
  								            else if (c > 32) return true;
  								        }
  								    }
  								}
  
  										     static class Pair implements Comparable<Pair>{
  										            public long x, y,z;
  										            public Pair(long x1, long y1,long z1) {
  										                x=x1;
  										                y=y1;
  										                z=z1;
  										            }
  										             public Pair(long x1, long y1) {
  										                x=x1;
  										                y=y1;
  										    
  										            }
  										            
  										            @Override
  										            public int hashCode() {
  										                return (int)(x + 31 * y);
  										            }
  										            public String toString() {
  										                return x + " " + y+" "+z;
  										            }
  										            @Override
  										            public boolean equals(Object o){
  										                if (o == this) return true;
  										                if (o.getClass() != getClass()) return false;
  										                Pair t = (Pair)o;
  										                return t.x == x && t.y == y&&t.z==z;
  										            }
  										    public int compareTo(Pair o)
  										    {
  										    								  	
  										  
  										  	return (int)(y-o.y);
  
  										    	
  										     
  										        }
  										     
  										    }
  										}
  										
  										    
  										   
  
  										     
  