#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const ll N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;
ll w[N] , a[N] , b[N] , ord[N] , d[N] , c[N] , n , q;
vector<long long> solve(){
	vector<ll> vec;
	for(int _ = 1; _ <= q; _++){
		ll sum = 0;
		for(int i = 1; i <= n; i++){
			// sum += b[i];
			// с[i] = a[i]-b[i];
			ord[i] = i;
		}
		sort(ord+1,ord+1+n,[&](int i , int j){
			return w[i] < w[j];
		});
		ll ans = 0;
		for(int l = 1; l <= n; l++){
			if(l+1 <= n){
				int i = ord[l];
				int j = ord[l+1];
				if(abs(w[i]-w[j]) <= d[_]){
					ans += 2;
					l++;
				} else {
					ans += 2;
				}
			} else {
				ans += 2;
			}
		}
		vec.push_back(ans);
	}
	return vec;
}
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E){
	n = W.size();
	for(int i = 1; i <= n; i++){
		w[i] = W[i-1];
		a[i] = A[i-1];
		b[i] = B[i-1];
	}
	q = E.size();
	for(int i = 1; i <= q; i++){
		d[i] = E[i-1];
	}
	return solve();
}
// int main() {
  // int N;
  // assert(1 == scanf("%d", &N));
  // std::vector<int> W(N), A(N), B(N);
  // for (int i = 0; i < N; i++)
    // assert(3 == scanf("%d%d%d", &W[i], &A[i], &B[i]));
  // int Q;
  // assert(1 == scanf("%d", &Q));
  // std::vector<int> E(Q);
  // for (int j = 0; j < Q; j++)
    // assert(1 == scanf("%d", &E[j]));
  // fclose(stdin);
// 
  // std::vector<long long> R = calculate_costs(W, A, B, E);
// 
  // int S = (int)R.size();
  // for (int j = 0; j < S; j++)
    // printf("%lld\n", R[j]);
  // fclose(stdout);
// 
  // return 0;
// }
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |