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++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(long long i=(long long)(m) ; i < (long long) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;

const long long inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

signed main(){
	long long n;
	cin>>n;
	long long m;
	cin>>m;
	long long a[m];
	rep(i,m)cin>>a[i];
	long long sum[m+1];
	sum[m]=0;
	rep(i,m-1)sum[i]=a[i+1]-a[i]-1;
	sum[m-1]=n-a[m-1];
	sort(sum,sum+m);
	long long b[m];
	rep(i,m)b[i]=sum[i];
	rep(i,m-1)sum[m-i-2]+=sum[m-i-1];
	long long ans[n+1];
	ans[0]=longinf;
	REP(i,1,n+1){
		long long idx=lower_bound(b,b+m,i)-b;
		ans[i]=sum[idx]-(m-idx)*(i-1);
	}
	rep(i,n+1)ans[i]=-ans[i];
	long long q;
	cin>>q;
	while(q--){
		long long x;
		cin>>x;
		x-=a[0]-1;
		if(x<0){
			cout<<-1<<endl;
		}
		else {
			long long ret=lower_bound(ans,ans+n+1,-x)-ans;
			cout<<ret<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> w(m+1);
	for(int i=0; i<m; i++){
		cin >> w[i];
	}
	w[m] = n+1;
	int q;
	cin >> q;
	vector<int> query(q);
	for(int i=0; i<q; i++){
		cin >> query[i];
	}

	vector<int> loss(n+2,0),num(n+2,0);
	loss[0] += w[0]-1;
	num[0] += m;
	for(int i=0; i<m; i++){
		int len = w[i+1] -w[i];
		loss[0] += len;
		loss[len+1] -= len;
		num[len+1] -= 1;
	}
	for(int i=0; i<n+2; i++){
		loss[i+1] += loss[i];
		num[i+1] += num[i];
	}
	for(int i=0; i<n+2; i++){
		loss[i] -= num[i]*i;
		loss[i] = -loss[i];
	}

	for(int i=0; i<q; i++){
		if(-loss[n+1] > query[i]){
			cout << -1 << endl;
		}else{
			auto itr = lower_bound(loss.begin(), loss.end(), -query[i]);
			int ans = itr -loss.begin();
			cout << max(1, ans) << endl;
		}
	}
	return 0;
}