Problem:
D: 矢 / Arrow
問題
rodea 君は 1 次元座標系の中におり、
x = 0
の場所に立っている。この位置から、
x = N
の位置にある的を目がけて、 常に速さ
1
で移動する正の整数の長さの矢を投げる。しかし、rodea 君は非力なため、  区間
0 \leq x \leq N
の中に合計
M
個の送風機を置くことにしている。
ここで、矢の先端から根元までの位置に
1
つの送風機も含まれない場合を「損失」と定義する。損失の判定は、矢の先端が
x = 1, 2, 3,
$\ldots$
, N
に到達した際に行う（つまり、合計
N
回行う）。
このとき、以下のクエリを
Q
回処理せよ。
「損失」許容可能な回数
l_i
が与えられる。すなわち、
N
回の判定において、「損失」が合計
l_i
回以下なら矢を的に届けることが可能である。このときの、矢を的に届けるために必要な最短の矢の長さを求める。
入力形式
N
M
m_1
m_2
$\ldots$
m_M
Q
l_1
l_2
$\ldots$
l_Q
1
行目に距離
N
と送風機の個数
M
が空白区切りで与えられる。
2
行目に、
M
個の送風機それぞれの位置が与えられる。
m_i=j
のとき、
i
番目の送風機は
x=j-1
と
x=j
の丁度中間に位置している。
3
行目にクエリの個数
Q
が与えられ、
4
行目に「損失」許容可能な回数
l_i
が
Q
個与えられる。
制約
1 \leq N \leq 10^5
1 \leq M \leq N
1 \leq m_1 < m_2 <
$\ldots$
< m_M \leq N
1 \leq Q \leq 10^5
0 \leq l_i \leq 10^5
(
1 \leq i \leq Q
)
出力形式
与えられる
Q
個の
l_i
に対して考えられる最短の矢の長さを、順に改行して出力せよ。
ただし、条件を満たす正の整数の長さの矢が存在しない場合は
-1
を出力するものとする。
入力例1
5 1
2
1
3
出力例1
2
矢の先端が
x = 1
に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は
1
になる。
矢の先端が
x = 2
に到達したとき、先端から根元までに送風機は含まれるので、「損失」回数は
1
のままである。
矢の先端が
x = 3
に到達したとき、先端から根元までに送風機は含まれるので、「損失」回数は
1
のままである。
矢の先端が
x = 4
に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は
2
になる。
矢の先端が
x = 5
に到達したとき、先端から根元までに送風機は含まれないので、「損失」回数は
3
になる。
長さ
2
より短い矢を投げる場合、「損失」回数が
3
よりも多くなるため、長さ
2
の矢を投げるときが条件を満たす最短の矢の長さである。
入力例2
11 3
2 5 9
3
1 4 8
出力例2
4
3
1

Submitted solutions:

code_snippet: #pragma region Macros
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

using ull = unsigned long long;
using ld = long double;
using int128 = __int128_t;
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define uniqv(v) v.erase(unique(all(v)), v.end())
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define log(x) cout << x << endl
#define logfixed(x) cout << fixed << setprecision(10) << x << endl;
#define logy(bool)         \
  if (bool) {              \
    cout << "Yes" << endl; \
  } else {                 \
    cout << "No" << endl;  \
  }

ostream &operator<<(ostream &dest, __int128_t value) {
  ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(ios_base::badbit);
    }
  }
  return dest;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++) {
    os << v[i] << (i + 1 != (int)v.size() ? " " : "");
  }
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    ++itr;
    if (itr != set_var.end()) os << " ";
    itr--;
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << itr->first << " -> " << itr->second << "\n";
  }
  return os;
}

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}

void out() { cout << '\n'; }
template <class T, class... Ts>
void out(const T &a, const Ts &...b) {
  cout << a;
  (cout << ... << (cout << ' ', b));
  cout << '\n';
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
  cin >> first;
  in(rest...);
  return;
}

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<lint> dx8 = {1, 1, 0, -1, -1, -1, 0, 1};
vector<lint> dy8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<lint> dx4 = {1, 0, -1, 0};
vector<lint> dy4 = {0, 1, 0, -1};

#pragma endregion

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> M(m);
  rep(i, m) cin >> M[i];
  vector<int> dist(m - 1);
  rep(i, m - 1) {
    dist[i] = M[i + 1] - M[i];
  }
  sort(all(dist));
  vector<lint> ac(m, 0);
  rep(i, m - 1) ac[i + 1] = ac[i] + dist[i];

  int Q;
  cin >> Q;
  while (Q--) {
    int l;
    cin >> l;
    if (l < M[0] - 1) {
      out(-1);
      continue;
    }
    int ng = 0, ok = n;
    while (ok - ng > 1) {
      int mid = (ok + ng) / 2;
      int sum = M[0] - 1;
      if (m != 1) {
        int x = upper_bound(all(dist), mid) - dist.begin();
        int val = ac.back() - ac[x];
        val -= (m - 1 - x) * mid;
        sum += val;
      }
      sum += max(n - M.back() + 1 - mid, 0);
      if (sum <= l)
        ok = mid;
      else
        ng = mid;
    }
    out(ok);
  }
}
accuracy: 1
time_ms: 40
memory_kb: 4668
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
#define all(x) x.begin(),x.end()
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
const int INF = 1000000;
int main() {
    int n, m;
    cin >> n >> m;

    vector<int> a(m);

    rep(i, m) cin >> a[i];

    vector<bool> placed(n - 1);

    rep(i, m) {
        placed[a[i] - 1] = true;
    }

    vector<int> v(100001);

    int c0 = -1;
    for (int i = 0; i < n; ++i) {
        if (placed[i]) {
            c0 = i;
            break;
        }
    }
    if (c0 == -1) {
        c0 = n;
    }
    int cnt = 0;
    for (int i = c0; i < n; ++i) {
        if (!placed[i]) {
            cnt++;
        } else {
            if (cnt != 0) {
                v[cnt]++;
            }
            cnt = 0;
        }
    }

    if (cnt != 0) {
        v[cnt]++;
    }

    vector<int> res(100002);
    int sum = 0;

    for (int i = 100000; i >= 1; --i) {
        res[i] = res[i + 1] + sum + v[i];
        sum += v[i];
    }

    vector<int> ans(100002, INF);

    for (int i = 1; i <= 100000; ++i) {
        chmin(ans[res[i] + c0], i);
    }
    for (int i = 1; i <= 100000; ++i) {
        chmin(ans[i], ans[i - 1]);
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; ++i) {
        int l;
        cin >> l;
        if (ans[l] == INF) cout << -1 << '\n';
        else cout << ans[l] << '\n';
    }
}
accuracy: 1
time_ms: 90
memory_kb: 4572
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=9167167167167167167;
const int INF=100000000;
const ll mod=998244353;
#define rep(i,a) for (int i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

// return val=p(N)
// a=p[0].first^p[0].second * ... *p[N-1].first^p[N-1].second
// for all i: p[i].first is prime number
// O(sqrt(val))
std::vector<std::pair<long long,long long>> Prime_factorization(long long val){
	assert(val>=1);
	if(val==1){
		return {};
	}
	int ind=0;
	std::vector<std::pair<long long,long long>> ans;
	for(long long i=2;i*i<=val;i++){
		if(val%i!=0) continue;
		ans.push_back({i,0});
		while(val%i==0){
			ans[ind].second++;
			val/=i;
		}
		ind++;
	}
	if(val!=1) ans.push_back({val,1});
	return ans;
}
 
void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M;
	cin>>N>>M;
	vector<int> p(N,INF);
	vector<int> order;
	rep(i,M){
		int a;
		cin>>a;
		a--;
		p[a]=1;
		order.push_back(a);
	}
	int L=1e5+10;
	vector<int> q(L);
	int ind=0;
	while (ind!=(int)(order.size()))
	{
		int a=order[ind];
		ind++;
		if(a+1<N&&p[a+1]==INF){
			p[a+1]=p[a]+1;
			order.push_back(a+1);
		}
		q[p[a]]++;
	}
	rep(i,L-1) q[i+1]+=q[i];
	q[0]=-INF;
	int Q;
	cin>>Q;
	rep(i,Q){
		int a;
		cin>>a;
		int b=LB(q,N-a);
		if(b==L) cout<<"-1\n";
		else cout<<b<<"\n";
	}
}
accuracy: 1
time_ms: 10
memory_kb: 4540
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
using namespace std;
template<typename T>
struct BIT{//1_Indexed
  int n;
  vector<T> bit;
  BIT(int n_):n(n_+10),bit(n_+5,0){}

  T sum(int a){
  int ret = 0;
  for(int i = a; i > 0; i -= i & -i) ret += bit[i];
  return ret;
  }

  void add(int a,int w){
    for(int i = a; i <= n; i += i & -i)bit[i] += w;
  }

  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }

  int lower_bound(T w){
    if(w <= 0){
      return 0;
    }else{
      int x = 0, r = 1;
      while(r < n) r = r<<1;
      for(int len = r; len > 0; len = len >> 1){
        if(x + len < n && bit[x + len] < w){
          w -= bit[x + len];
          x += len;
        }
      }
      return x + 1;
    }
  }

};



int main(){
  int n,m;cin>>n>>m;
  vector<int> A(m);
  for(int i = 0; m > i; i++){
    cin>>A[i];
  }
  int nw = n+1;
  BIT<int> X(n+3);
  int nwp = 0;
  for(int i = 1; n >= i; i++){
    if(nwp < A.size() && i == A[nwp]){
      nw = 1;
      nwp++;
    }else if(nw != n+1){
      nw++;
    }
    X.add(nw,1);
  }
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    int l;cin>>l;
    int x = X.lower_bound(n-l);
    //cout << x << endl;
    if(x == n+1){
      cout << -1 << endl;
    }else{
      cout << max(1,x) << endl;
    }
  }
}
accuracy: 1
time_ms: 100
memory_kb: 3868
final_rank: 3

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<map>
#include<unistd.h>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

int N, M;
int b, L;
vector<int> m;
vector<int> s, c;

bool check(int num){
	if(num >= N) return true;
	if(num <= 0) return false;
	
	int t = 0;
	
	t = s[N] - s[num-1] - (c[N] - c[num-1]) * (num-1);
	
	return b + t <= L;
}

signed main(){
	cout<<fixed<<setprecision(10);
	
	
	
	cin>>N>>M;
	
	s.resize(N+1);
	c.resize(N+1);
	
	m.resize(M+1);
	m[M] = N+1;
	
	for(int i = 0; i < M; i++){
		cin>>m[i];
	}
	
	b = m[0]-1;
	
	for(int i = 1; i < (int)m.size(); i++){
		if(m[i] - m[i-1] == 0) continue;
		s[m[i] - m[i-1] - 1] += (m[i] - m[i-1] - 1);
		c[m[i] - m[i-1] - 1] += 1;
	}
	
	for(int i = 1; i < (int)s.size(); i++){
		s[i] += s[i-1];
		c[i] += c[i-1];
	}
	
	int Q;
	
	cin>>Q;
	
	for(int i = 0; i < Q; i++){
		
		cin>>L;
		
		if(L < b) {
			cout<<-1<<endl;
			continue;
		}
		
		int l = 0, r = N+1, m;
		
		while(l + 1 < r){
			m = (l + r) / 2;
			
			if(check(m)) {
				r = m;
			} else {
				l = m;
			}
		}
		
		cout<<r<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5360
final_rank: 6

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

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvec = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e9+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return (a + b - 1) / b; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
	const int max_n = 1e5+10;
	int N, M; cin >> N >> M;
	vector<int> m(M+1); rep(i, M) cin >> m[i]; m[M] = N+1;

	vector<int> inv(max_n+1);
	priority_queue<int, vector<int>, greater<int>> sukima;

	rep(i, M) sukima.push(m[i+1] - m[i]);

	inv[0] = 0;
	int adNoLos = M;
	rep(i, max_n){
		inv[i+1] = inv[i];
		while(1){
			if(sukima.empty()) break;
			if(sukima.top() < i+1){
				adNoLos--;
				sukima.pop();
			}
			else break;
		}
		inv[i+1] += adNoLos;
	}
	rep(i, max_n+1){
		inv[i] = N - inv[i];
	}

	int Q; cin >> Q;
	while(Q--){
		int l; cin >> l;
		ll L = 1, R = N, mid;
		while(L != R){
			mid = (L + R) / 2;
			(inv[mid] <= l) ? R = mid : L = mid + 1;
		}
		if(R == N && inv[R] > l) cout << -1 << endl;
		else cout << R << endl;
	}
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5716
final_rank: 7

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

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvec = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
const int MOD = 998244353;
//const int MOD = 1e9+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return (a + b - 1) / b; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
	const int max_n = 1e5+10;
	int N, M; cin >> N >> M;
	vector<int> m(M+1); rep(i, M) cin >> m[i]; m[M] = N+1;

	vector<int> inv(max_n+1);
	priority_queue<int, vector<int>, greater<int>> sukima;

	rep(i, M) sukima.push(m[i+1] - m[i]);

	inv[0] = 0;
	int adNoLos = M;
	rep(i, max_n){
		inv[i+1] = inv[i];
		while(1){
			if(sukima.empty()) break;
			if(sukima.top() < i+1){
				adNoLos--;
				sukima.pop();
			}
			else break;
		}
		inv[i+1] += adNoLos;
	}
	rep(i, max_n+1){
		inv[i] = N - inv[i];
	}

	reverse(all(inv));
	auto it = inv.begin();

	int Q; cin >> Q;
	while(Q--){
		int l; cin >> l;
		it = upper_bound(all(inv), l);
		if(it == inv.begin()){
			cout << inv[0] << endl;
			cout << -1 << endl;
		}
		else{
			cout << max((int)(inv.end() - it), (int)1) << endl;
		}
	}
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 0.15625
time_ms: 10
memory_kb: 4688
final_rank: 15

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    i64 n, m;
    cin >> n >> m;
    vector<i64> x(m);
    for (auto &vs : x) cin >> vs;
    vector<i64> d(m);
    d[m - 1] = n - x[m - 1] + 1;
    rep(i, m - 1) d[i] = x[i + 1] - x[i];

    sort(ALL(d));

    vector<i64> dsum(n + 1);
    vector<i64> cnt(n + 1);
    for (auto vs : d) {
        dsum[vs] += vs;
        cnt[vs]++;
    }
    rep(i, 1, n + 1) {
        dsum[i] += dsum[i - 1];
        cnt[i] += cnt[i - 1];
    }

    /*
    rep(i, n + 1) { cout << dsum[i] << ' '; }
    cout << endl;
    rep(i, n + 1) { cout << cnt[i] << ' '; }
    cout << endl;
    */

    i64 q;
    cin >> q;
    rep(_, q) {
        i64 l;
        cin >> l;

        auto f = [&](i64 mid) {
            return (dsum[n] - dsum[mid]) - mid * (m - cnt[mid]) + x[0] - 1;
        };

        i64 valid = n + 1, invalid = 0;
        while (valid - invalid > 1) {
            i64 mid = (valid + invalid) / 2;
            // cout << mid << ' ' << f(mid) << endl;
            if (f(mid) <= l)
                valid = mid;
            else
                invalid = mid;
        }

        // rep(i, 1, n) { cout << f(i) << ' '; }
        // cout << endl;

        if (invalid == n)
            cout << -1 << '\n';
        else
            cout << valid << '\n';
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6100
final_rank: 10

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

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    bool exist[n];
    memset(exist, false, sizeof(exist));
    rep(i, m) {
        int p;
        scanf("%d", &p);
        --p;
        exist[p] = true;
    }

    int a[n + 1];
    memset(a, 0, sizeof(a));
    int offset = 0;
    for (int l = 0; l < n;) {
        if (exist[l]) {
            ++l;
            continue;
        }
        int r = l;
        while (r < n && !exist[r]) ++r;
        if (l == 0) {
            offset = r;
        } else {
            ++a[r - l];
        }
        l = r;
    }
    rrep(i, n) a[i] += a[i + 1];
    a[n] += offset;
    rrep(i, n) a[i] += a[i + 1];

    int q;
    scanf("%d", &q);
    rep(i, q) {
        int l;
        scanf("%d", &l);
        if (a[n] > l)
            puts("-1");
        else {
            int low = 0, high = n;
            while (high - low > 1) {
                int mid = (high + low) / 2;
                (a[mid] <= l ? high : low) = mid;
            }
            printf("%d\n", high);
        }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 4056
final_rank: 1

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-3, PI = acos(-1);
//ここから編集


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  int N, M; cin >> N >> M;

  vector<int> m(M);
  REP(i,M) cin >> m[i];
  int q;
  cin >> q;
  vector<pair<int, int>> l(q);
  REP(i,q) {
    cin >> l[i].first, l[i].second = i;
    
  }
  sort(all(l));
  reverse(all(l));
  vector<int> ans(q, -1);
  multiset<int> st;
  ll sum = 0;
  for(int i=1; i<M; i++){
    st.insert(m[i]-m[i-1]-1);
    sum += m[i]-m[i-1]-1;
  }
  st.insert(N-m[M-1]);
  sum += N - m[M-1];
  
  // for(auto e: st){
  //   cout << e << " ";
  // }
  // cout << endl;
  int idx = 0;
  for(int i=1; i<=N; i++){ 
    while(idx<q && l[idx].first >= sum - st.size()*(i-1) + m[0]-1){
      ans[l[idx].second] = i;
      idx++;
    }

    while(st.size() && *st.begin() < i){
      sum -= *st.begin();
      auto itr = st.find(*st.begin());
      st.erase(itr);
    }

  }
  for(int i=0; i<q; i++){
    cout << ans[i] << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 9164
final_rank: 14

code_snippet: #include <bits/stdc++.h>
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(x,a) for(auto &x:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = 1001002003;
const ll      LINF= 1001002003004005006LL;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

void _main() {
  int N, M;   cin >> N >> M;
  vi m(M);
  vi exists(N+1);
  rep(i, 0, M) {
    cin >> m[i];
    --m[i];
    ++exists[m[i]];
  }

  const int M1 = find(all(exists), 1) - exists.begin();
  vi d;
  {
    d.pb(0);
    int cnt = 0;
    rep(i, M1+1, N) {
      if (exists[i]) {
        d.pb(cnt);
        cnt = 0;
      } else {
        ++cnt;
      }
    }
    if (cnt) d.pb(cnt);
    sort(all(d));
  }

  vi B(N);
  {
    int sum = accumulate(all(d), 0);
    int di = 0;
    rep(i, 0, N) {
      // trace3(i, di, sum);
      B[i] = sum + M1;
      while (di < sz(d) && d[di]-i <= 0) ++di;
      sum -= (sz(d)-di);
    }
    reverse(all(B));
  }
  // cout << endl;
  // trace2(N, M);
  // trace1(m);
  // trace1(exists);
  // trace1(d);
  // trace1(B);

  int Q;    cin >> Q;
  vi l(Q);  fore(x, l) cin >> x;
  vi ans(Q);
  rep(i, 0, Q) {
    int tmp = N + 1 - (upper_bound(all(B), l[i]) - B.begin());
    ans[i] = (0 < tmp &&  tmp <= N) ? tmp : -1;
  }
  fore(x, ans) cout << x << endl;
}
accuracy: 1
time_ms: 100
memory_kb: 5216
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(x,a) for(auto &x:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = 1001002003;
const ll      LINF= 1001002003004005006LL;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

void _main() {
  int N, M;   cin >> N >> M;
  vi m(M);
  vi exists(100001);
  rep(i, 0, M) {
    cin >> m[i];
    --m[i];
    ++exists[m[i]];
  }

  int add = 0;
  vi al;
  {
    int cnt = 0;
    bool f = false;
    rep(i, 0, N) {
      if (!f) {
        if (exists[i]) f = true;
        else      ++add;
      } else {
        if (exists[i]) {
          al.pb(cnt);
          cnt = 0;
        } else {
          ++cnt;
        }
      }
    }
    if (cnt) al.pb(cnt);
  }

  int sum = 0;
  fore(x, al) sum += x;
  sort(all(al));
  vi B(N);
  int idx = 0;
  rep(i, 0, N) {
    B[i] = sum + add;
    while (idx < sz(al) && al[idx]-i <= 0) ++idx;
    sum -= (sz(al)-idx);
  }
  reverse(all(B));

  int Q;    cin >> Q;
  vi l(Q);  fore(x, l) cin >> x;
  vi ans(Q);
  rep(i, 0, Q) {
    int tmp = N + 1 - (upper_bound(all(B), l[i]) - B.begin());
    ans[i] = (0 < tmp &&  tmp <= N) ? tmp : -1;
  }
  fore(x, ans) cout << x << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 5316
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(x,a) for(auto &x:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = 1001002003;
const ll      LINF= 1001002003004005006LL;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

void _main() {
  int N, M;   cin >> N >> M;
  vi m(M);
  vi exists(100001);
  rep(i, 0, M) {
    cin >> m[i];
    --m[i];
    ++exists[m[i]];
  }

  int add = 0;
  vi al;
  {
    int cnt = 0;
    bool f = false;
    rep(i, 0, N) {
      if (!f) {
        if (exists[i]) f = true;
        else      ++add;
      } else {
        if (exists[i]) {
          al.pb(cnt);
          cnt = 0;
        } else {
          ++cnt;
        }
      }
    }
    if (cnt) al.pb(cnt);
  }

  int sum = 0;
  fore(x, al) sum += x;
  sort(all(al));
  vi B(N);
  int idx = 0;
  rep(i, 0, N) {
    B[i] = sum + add;
    while (idx < sz(al) && al[idx]-i <= 0) ++idx;
    sum -= (sz(al)-idx);
  }
  reverse(all(B));

  int Q;    cin >> Q;
  vi l(Q);  fore(x, l) cin >> x;
  vi ans(Q);
  rep(i, 0, Q) {
    int tmp = N + 1 - (upper_bound(all(B), l[i]) - B.begin());
    if (tmp <= 0 || tmp > N) ans[i] = -1;
    ans[i] = tmp;
  }
  fore(x, ans) cout << x << endl;
}
accuracy: 0.15625
time_ms: 90
memory_kb: 4640
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(x,a) for(auto &x:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = 1001002003;
const ll      LINF= 1001002003004005006LL;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

int N, M;
vi m;
int Q;
vi l;

vi c(100001);
vi A(100001);
vi al;
vi B;

int solve(int i) {
  int idx = upper_bound(all(B), l[i]) - B.begin();
  int ret = N-idx+1;
  if (ret <= 0 || ret > N) return -1;
  return ret;
}

void _main() {
  cin >> N >> M;
  m.resize(M);
  rep(i, 0, M) {
    cin >> m[i];
    --m[i];
    ++c[m[i]];
  }

  int add = 0;
  {
    int cnt = 0;
    bool f = false;
    rep(i, 0, N) {
      if (!f) {
        if (c[i]) {
          f = true;
        } else {
          ++add;
        }
      } else {
        if (c[i]) {
          ++A[cnt];
          al.pb(cnt);
          cnt = 0;
        } else {
          ++cnt;
        }
      }
    }
    if (cnt) al.pb(cnt);
  }

  int sum = 0;
  fore(x, al) sum += x;
  sort(all(al));
  B.resize(N);
  int idx = 0;
  rep(i, 0, N) {
    B[i] = sum + add;
    while (idx < sz(al) && al[idx]-i <= 0) ++idx;
    sum -= (sz(al)-idx);
  }
  reverse(all(B));

  cin >> Q;
  l.resize(Q); fore(x, l) cin >> x;
  vi ans(Q);
  rep(i, 0, Q) ans[i] = solve(i);
  fore(x, ans) cout << x << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 5824
final_rank: 11

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  // 最短の矢の長さ（or-1）
  // 矢の長さをxとすると
  // l>=N-(x*M)を満たす最低のxが答え
  // N*l/M<=x
  // しかし当然ながら扇風機の範囲がかぶるところが存在する
  // xを順に伸ばして言ってDPに損失を保存していく
  int N,M;cin>>N>>M;
  vector<int> ms(M);
  REP(i,M) cin>>ms[i];

  // 損失にならない場はtrue
  bitset<100000> bs;
  REP(i,M) bs.set(N-1-(ms[i]-1));

  // 長さがiの時の損失の数をdp[i-1]とする
  vector<ll> dp(N,0);
  dp[0] = N-M;

  // 余計なzeroの数
  int red = 100000 - N;

  FOR(n,1,N) {
    bs |= bs>>1;
    dp[n] = 100000 - bs.count()-red;
  }
  // DUMP(dp);

  int Q;cin>>Q;

  // 逆順にして、l+1のlower_bound-begin-1=idxとしたとき、N-idxが答え
  reverse(ALL(dp));

  REP(i,Q) {
    int l;cin>>l;
    if (dp[0]>l) {
      OUT(-1);
    } else {
      ll idx = lower_bound(ALL(dp),l+1)-dp.begin()-1;
      OUT(N-idx);
    }
  }

  return 0;
}
accuracy: 1
time_ms: 710
memory_kb: 4164
final_rank: 13

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

int main() {
  // 最短の矢の長さ（or-1）
  // 矢の長さをxとすると
  // l>=N-(x*M)を満たす最低のxが答え
  // N*l/M<=x
  // しかし当然ながら扇風機の範囲がかぶるところが存在する
  // xを順に伸ばして言ってDPに損失を保存していく
  int N,M;cin>>N>>M;
  vector<int> ms(M);
  REP(i,M) cin>>ms[i];

  // 損失にならない場はtrue
  bitset<100000> bs;
  REP(i,M) bs.set(N-1-(ms[i]-1));

  // 長さがiの時の損失の数をdp[i-1]とする
  vector<ll> dp(N,0);
  dp[0] = N-M;

  // 余計なzeroの数
  int red = 100000 - N;

  FOR(n,1,N) {
    bs |= bs>>1;
    dp[n] = 100000 - bs.count()-red;
  }
  // DUMP(dp);

  int Q;cin>>Q;

  // 逆順にして、l+1のlower_bound-begin-1=idxとしたとき、N-idxが答え
  reverse(ALL(dp));

  REP(i,Q) {
    int l;cin>>l;
    if (dp[0]>l) {
      OUT(-1);
      break;
    } else {
      ll idx = lower_bound(ALL(dp),l+1)-dp.begin()-1;
      OUT(N-idx);
    }
  }

  return 0;
}
accuracy: 0.15625
time_ms: 480
memory_kb: 3564
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace7(a, b, c, d, e, f , g) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | "<< #g <<": "<<g<<endl
#define trace8(a, b, c, d, e, f , g , h) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<< f << " | " << #g <<": "<< g <<" | "<<#h<< ": " << h << endl
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(x,a) for(auto &x:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define dup(x,y) (((x)+(y)-1)/(y))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(a) ((long long)(a).size())
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = 1001002003;
const ll      LINF= 1001002003004005006LL;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

int N, M;
vi m;
int Q;
vi l;
vi d(100001);
vi d_cnt(100001);

int solve(int i) {
  int a = l[i];
  int ret = sz(d_cnt) - (upper_bound(all(d_cnt), a) - d_cnt.begin());
  if (ret == sz(d_cnt)) ret = -1;
  return ret;
}

void _main() {
  cin >> N >> M;
  m.resize(M);  fore(x, m) cin >> x;
  cin >> Q;
  l.resize(Q);  fore(x, l) cin >> x;

  // trace1(l);
  // trace1(m);
  ++d[m[0]];
  // rep(i, 0, Q-1) ++d[m[i+1] - m[i]];
  rep(i, 0, M-1) {
    ++d[m[i+1] - m[i]];
  }
  ++d[N - m[M-1]];

  int cnt = M + 1;
  int remain = N;
  d_cnt[0] = INF;
  rep(i, 1, 100001) {
    cnt -= d[i];
    remain -= i*d[i];
    d_cnt[i] = remain - cnt + 1;
  }
  sort(all(d_cnt));
  // trace1(d);
  // trace1(d_cnt);

  vi ans(Q);
  rep(i, 0, Q) ans[i] = solve(i);
  fore(x, ans) cout << x << endl;
}
accuracy: 0.0625
time_ms: 80
memory_kb: 4416
final_rank: 20

code_snippet: // template version 1.14
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int n,m;
vector<int> x;

signed main() {
  cin>>n>>m;

  x.resize(m);
  vi d;
  rep(i, m) { cin>>x[i]; }
  x.pb(n+1);
  rep(i, 1, m+1){
    d.pb(x[i]-x[i-1]);
  }
  sort(all(d));
  dump(d);

  vi dp(n+1);
  dp[1] = n-m;
  rep(y, 2, n+1){
    int x = posl(d, y);
    int v = (sz(d)) - x;
    dump(y, x);
    dp[y] = dp[y-1]-v;
  }
  dump(dp);

  vi ans(100001, -1);
  rrep(i, 1, n+1){
    ans[dp[i]] = i;
  }
  rep(i, 1, 100001){
    if (ans[i]==-1) ans[i]=ans[i-1];
  }

  int Q;cin>>Q;
  rep(i, Q) {
    int s;cin>>s;
    cout << ans[s] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 5928
final_rank: 12

code_snippet: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

vector<int> v;
int N,M,Q,m,l,now=0,dist[100100],cost[100100],sum=0;

int main(){
    cin>>N>>M;
    rep(i,M){
        cin>>m;
        dist[m-now]++;
        sum+=m-now;
        now=m;
    }
    dist[N-m]++;
    sum+=N-m;
    // rep(i,N)out(dist[i]);
    for(int i=N+10; i>0; i--){
        dist[i-1] = min(M,dist[i-1]+dist[i]);
    }
    cost[0]=N;
    repi(i,1,100010){
        cost[i]=cost[i-1]-dist[i-1];
    }
    cin>>Q;
    rep(i,Q){
        cin>>l;
        int left=0,right=N,mid;
        mid=(left+mid)/2;
        while(left<right){
            if(cost[mid]<=l){
                right=mid;
            }
            else{
                left=mid+1;
            }
            mid=(left+right)/2;
        }
        if(left==N)out(-1);
        else out(right);
    }

}
accuracy: 0.0625
time_ms: 100
memory_kb: 3512
final_rank: 18

code_snippet: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

vector<int> v;
int N,M,Q,m,l,now=0,dist[100100],cost[100100],sum=0;

int main(){
    cin>>N>>M;
    rep(i,M){
        cin>>m;
        dist[m-now]++;
        sum+=m-now;
        now=m;
    }
    dist[N-m]++;
    sum+=N-m;
    // rep(i,N)out(dist[i]);
    for(int i=N+10; i>0; i--){
        dist[i-1] = min(M,dist[i-1]+dist[i]);
    }
    cost[0]=N;
    repi(i,1,100010){
        cost[i]=cost[i-1]-dist[i-1];
    }
    cin>>Q;
    rep(i,Q){
        cin>>l;
        int left=0,right=N,mid;
        mid=(left+mid)/2;
        while(left<right){
            if(cost[mid]<=l){
                right=mid;
            }
            else{
                left=mid+1;
            }
            mid=(left+right)/2;
        }
        out(right);
    }
    // rep(i,N)out(cost[i]);
}
accuracy: 0.0625
time_ms: 100
memory_kb: 3528
final_rank: 19