Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	m := sc.nextIntSlice(M)
	m = append(m, N)
	Q := sc.nextInt()
	l := sc.nextIntSlice(Q)
	base := m[0] - 1
	sums := make([]int, N+1)
	for i := 1; i <= M; i++ {
		var diff int
		if i != M {
			diff = m[i] - m[i-1] - 1
		} else {
			diff = m[i] - m[i-1]
		}
		for j := 0; j < diff; j++ {
			sums[j+1] += diff - j
		}
	}
	for _, allow := range l {
		ok := N + 1
		ng := 0
		for abs(ok-ng) > 1 {
			mid := (ok + ng) / 2
			if base+sums[mid] <= allow {
				ok = mid
			} else {
				ng = mid
			}
		}
		if ok == N+1 {
			fmt.Fprintln(wtr, -1)
		} else {
			fmt.Fprintln(wtr, ok)
		}
	}

	wtr.Flush()
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
long long cnt[300000] = {};
long long adding[300000] = {};
int main() {
#define int long long
	int n, m;
	cin >> n >> m;
	vector<long long> input;
	REP(i, m) {
		long long tmp;
		cin >> tmp;
		input.push_back(tmp);
	}
	input.push_back(n+1);
	sort(input.begin(), input.end());
	REP(i, input.size()-1) {
		cnt[input[i + 1] - input[i]-1]++;
	}
	long long tools = 0;
	for (int i = 200000; i >= 0; --i) {
		cnt[i] += cnt[i + 1];
		adding[i] += adding[i + 1];
		adding[i] += cnt[i];
	}
	int query;
	cin >> query;
	REP(test, query) {
		long long geko = 0;
		cin >> geko;
		geko -= input[0] - 1;
		if (geko < 0) {
			cout << -1 << endl;
			continue;
		}
		long long top = n-1;
		long long bot = 1;
		while (top - bot > 1) {
			long long mid = (top + bot) / 2;
			if (adding[mid] > geko) {
				bot = mid;
			}
			else {
				top = mid;
			}
		}
		for (int i = max(1LL, (long long)bot - 3);; ++i) {
			if (adding[i] <= geko) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
 
#define int long long
 
int N,M;
 
 
bool sou[101010];
 
int cnt[202020];
 
int fff = 0;
 
int ss[202020];
int sum[202020];
 
int func(int x) {
  int res = ss[101010 - 1] - ss[x - 1] - (sum[101010 -1] - sum[x - 1]) * (x - 1) + fff;
  return res;
}
 
 
 
signed main() {
  cin >> N >> M;
  for(int i = 0;i < M;i++) {
    int m;
    cin >> m;
    m--;
    sou[m] = true;
  }
 
  sou[N] = true;
 
  int fi = 0;
  while(!sou[fi]) fi++;
 
  fff = fi;
  {
    int c = 0;
    for(int i = fi;i <= N;i++) {
      if(sou[i]) {
        cnt[c]++;
        c = 0;
      }
      else {
        c++;
      }
    }
  }
 
  cnt[0] = 0;
 
  for(int i = 1;i < 101010;i++) {
    sum[i] += sum[i - 1] + cnt[i];
  }
 
  for(int i = 1;i < 101010;i++) {
    ss[i] += ss[i - 1] + cnt[i] * i;
  }
 
  int Q;
  cin >> Q;
  vector<int> ans;
  for(int qq = 0;qq < Q;qq++) {
    int l;
    cin >> l;
    int ok = 101010;
    int ng = 0;
    while(ok - ng > 1) {
      int mid = (ok + ng) / 2;
      if(func(mid) <= l) ok = mid;
      else ng = mid;
    }
    ans.push_back(ok);
  }
 
  for(auto x : ans) {
    if(x == 101010) { cout << -1 << endl; }
    else { cout << x << endl;}
  }
 
}