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<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
int n, m;
int x[1 << 17];

int ans[1 << 17];

priority_queue<int, vector<int>, greater<int>>q;
vector<P> vr;

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> x[i];
	}
	ans[1] = n - m;
	rep(i, m - 1) {
		if (x[i + 1] - x[i]-1 > 0)q.push(x[i + 1] - x[i] - 1);
	}
	//if (x[0] > 1)q.push(x[0] - 1);
	if (n - x[m - 1] > 0)q.push(n - x[m - 1]);
	Rep1(i, 2, n) {
		ans[i] = ans[i - 1] - q.size();
		while (!q.empty() && q.top() < i)q.pop();
		//cout << i << " " << ans[i] << endl;
	}
	rep1(i, n) {
		vr.push_back({ ans[i],i });
	}
	sort(vr.begin(), vr.end());
	int q; cin >> q;
	rep(aa, q) {
		int l; cin >> l;
		int id = lower_bound(vr.begin(), vr.end(), P{ l+1,-1 }) - vr.begin();
		if (id == 0)cout << -1 << endl;
		else {
			id--;
			int out = n - id;
			cout << out << endl;
		}
	}
	//stop
	return 0;
}

C++: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long

signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> v(M);
  for(int i=0;i<M;i++)cin>>v[i];
  map<int,int> m;
  for(int i=1;i<M;i++)m[v[i]-v[i-1]]++;
  m[N-v[M-1]+1]++;
  map<int,int> memo;
  int Q;cin>>Q;
  std::vector<int> iiii(Q);
  for(int i=0;i<Q;i++)cin>>iiii[i];
  for(int i=0;i<Q;i++){
    int L=iiii[i];
    L-=v[0]-1;
    if(L<0){cout<<-1<<endl;continue;}
    if(memo[L]){cout<<memo[L]<<endl;continue;}
    int l=0;int r=N+1;
    while(r-l>1){
      int me=(l+r)/2;
      int t=0;
      for(auto p:m){
        t+=max(p.first-me,0LL)*p.second;
      }
      if(t<=L)r=me;
      else l=me;
    }
    memo[L]=r;cout<<r<<endl;
  }
}

C++: #include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
//for CodeForces
#pragma GCC target("avx,avx2")
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
map<long long int, int>soinnsuu(long long int a) {
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;


	return ans;
}
struct query {
	int id;
	int num;
};
int main() {
	int N,M;cin>>N>>M;
	vector<int>v(M);
	for (int i = 0; i < M; ++i) { cin >> v[i]; };
	vector<int>nums;
	int need=v[0];
	for (int i = 0; i < M - 1; ++i) {
		nums.push_back(v[i+1]-v[i]);
	}
	nums.push_back(N-v.back()+1);
	map<int,int>mp;
	for (auto n : nums) {
		mp[n]++;
	}
	vector<int>anss(100005);
	anss[1]=N-M;
	int minus=M;
	for (int i = 2; i < 100005; ++i) {
		minus-=mp[i-1];
		anss[i]=anss[i-1]-minus;
	}
	anss.erase(anss.begin());
	reverse(anss.begin(),anss.end());
	int Q;cin>>Q;
	vector<pair<int,int>>qs;
	for (int i = 0; i < Q; ++i) {
		int a;cin>>a;
		qs.push_back(make_pair(a,i));
		auto it=lower_bound(anss.begin(),anss.end(),a+1);

		int nans=(anss.end()-it);
		if(it==anss.begin())nans=-2;
		cout<<nans+1<<endl;
	}



	vector<int>real_anss(Q);
	
	return 0;
}