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<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m);
    for(auto &I:a){cin>>I; I--;}
    ll l=0;
    vector<ll> L(n,0);
    for(int i=1;i<=n;i++){
        while(l<m && a[l]<i){l++;}
        if(l==0){L[i-1]=E;}
        else{L[i-1]=i-a[l-1];}
    }
    sort(L.begin(),L.end(),greater<ll>());
    ll q;
    cin>>q;
    while(q--){
        ll l;
        cin>>l;
        if(l>=n){cout<<1<<endl;}
        else if(L[l]==E){cout<<-1<<endl;}
        else{cout<<L[l]<<endl;}
    }
    
    
    
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
int p[125252];
int q;
int l[125252];
int ans[125252];  // ans[i] := length i arrow -> sonsitu

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m)scanf("%d",p+i),p[i]--;
  scanf("%d",&q);
  REP(i,q)scanf("%d",l+i);
  // calc ans
  REP(i,n+2)ans[i] += p[0];
  REP(i,m){
    int x = p[i];
    int y = i==m-1 ? n : p[i+1];
    int sp = y-x-1;
    int len = 1;
    while(sp>0){
      ans[len] += sp;
      len++; sp--;
    }
  }
  REP(i,n+2)ans[i] = n - ans[i];
  // query
  REP(i,q){
    int id = lower_bound(ans+1,ans+n+2,n-l[i]) - ans;
    if(id == n+2){
      puts("-1");
    }else{
      printf("%d\n",id);
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<LL> v(m+1);
  v[m]=n+1;
  for(int i=0;i<m;i++){
    cin >> v[i];
  }
  int h=v[0]-1;
  vector<LL> d(m),rui(m+1);
  for(int i=0;i<m;i++){
    d[i]=v[i+1]-v[i];
  }
  sort(all(d));
  rui[m]=0;
  for(int i=m-1;i>=0;i--){
    rui[i]=rui[i+1]+d[i];
  }
  // for(int i=0;i<m;i++){
  //   cout << d[i] << " ";
  // }
  // cout << endl;
  // for(int i=0;i<m;i++){
  //   cout << rui[i] << " ";
  // }
  // cout << endl;
  int q;
  cin >> q;
  LL k;
  for(int t=0;t<q;t++){
    cin >> k;
    LL l=0,r=IINF,mid;
    while(r-l>1){
      mid=(l+r)/2;
      int idx=distance(d.begin(),lower_bound(all(d),mid));
      // cout << mid SP idx SP rui[idx]-mid*(m-idx)+h << endl;
      if(rui[idx]-mid*(m-idx)+h<=k){
        r=mid;
      }else{
        l=mid;
      }
    }
    if(r==IINF){
      cout << -1 << endl;
    }else{
      cout << r << endl;
    }
  }
  return 0;
}