package laba7;

import java.util.Scanner;

public class example6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Timus 1787 — Turn for MEGA
        int k = sc.nextInt();
        int n = sc.nextInt();
        int queue = 0;
        for (int i = 0; i < n; i++) {
            queue += sc.nextInt();
            queue = Math.max(0, queue - k);
        }
        System.out.println(queue);

        // Timus 1209 — 1, 10, 100, 1000...
        int t = sc.nextInt();
        while (t-- > 0) {
            long x = sc.nextLong();
            long nVal = (long) ((Math.sqrt(8 * x - 7) - 1) / 2);
            System.out.println(nVal * (nVal + 1) / 2 + 1 == x ? 1 : 0);
        }
    }
}