1. Abridged Problem Statement  
Given n banks located along a line, each with coordinate xi and money wi (banks sorted by xi), pick two distinct banks i < j such that xj – xi ≥ d, maximizing wi + wj. Output their 1-based indices (any order), or “-1 -1” if no valid pair exists.

2. Detailed Editorial  

We need the best pair (i, j) with xi < xj and xj – xi ≥ d to maximize wi + wj. A brute-force O(n²) check is too slow for n up to 2·10^5, so we need an O(n log n) or O(n) approach.

Key observations:  
- The banks are already sorted by their coordinate xi.  
- For any index i (as the “left” bank), we want to find the smallest j > i with xj ≥ xi + d.  
- Once j is located, among all choices of left bank in [0..i] we want the one with maximum w, and among all choices of right bank in [j..n–1] we want the one with maximum w.

Algorithm:  
1. Read the array a of pairs (xi, wi).  
2. Build a prefix array pref where  
   pref[i] = pair(best_weight among a[0..i], index_of_that_bank).  
   Compute in a single left-to-right scan: pref[0] = (w0, 0);  
   pref[i] = max(pref[i–1], (wi, i)) by comparing weights.  
3. Build a suffix array suff where  
   suff[i] = pair(best_weight among a[i..n–1], index_of_that_bank).  
   Compute by scanning from right: suff[n–1] = (w[n–1], n–1);  
   suff[i] = max(suff[i+1], (wi, i)).  
4. Initialize answer sum = 0 and answer indices = (–1,–1).  
5. For each i = 0..n–1:  
   a. Use binary search (lower_bound) on a to find the first j with xj ≥ xi + d.  
   b. If no such j, continue. Otherwise the best pair using any left ≤ i and any right ≥ j has sum = pref[i].weight + suff[j].weight.  
   c. If this sum ≥ current best, update best and store the corresponding indices (1-based).  
6. Output the stored indices (or “-1 -1” if none found).

Complexities:  
- Building pref and suff: O(n).  
- For each i we do a binary search O(log n), so total O(n log n).  
- Memory O(n).  
This easily fits n ≤ 2·10^5, time limit 1.5s.

3. Provided C++ Solution with Detailed Comments  

```cpp
#include <bits/stdc++.h>
using namespace std;

// Overload << to print a pair as "first second"
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

// Overload >> to read a pair
template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

// Overload >> to read a vector element-wise
template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for (auto& x: a) {
        in >> x;
    }
    return in;
}

// Overload << to print a vector elements separated by spaces
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for (auto x: a) {
        out << x << ' ';
    }
    return out;
}

int n, d;
vector<pair<int, int>> a;  
// a[i] = {xi, wi}

// Read inputs
void read() {
    cin >> n >> d;
    a.resize(n);
    cin >> a; // uses overloaded >> to fill a
}

// Solve one test
void solve() {
    // pref[i] = {max_weight among a[0..i], index_of_that_bank}
    vector<pair<int, int>> pref(n), suff(n);

    // Build prefix maxima
    for (int i = 0; i < n; i++) {
        // Start with the current bank's weight and its index
        pref[i] = {a[i].second, i};
        // If not the first, compare with previous best
        if (i > 0) {
            pref[i] = max(pref[i], pref[i - 1]);
        }
    }

    // Build suffix maxima
    for (int i = n - 1; i >= 0; i--) {
        suff[i] = {a[i].second, i};
        if (i + 1 < n) {
            suff[i] = max(suff[i], suff[i + 1]);
        }
    }

    int bestSum = 0;
    pair<int,int> answer = {-1, -1};

    // For each possible left bank i
    for (int i = 0; i < n; i++) {
        // Find the first index j where xj >= xi + d
        auto it = lower_bound(
            a.begin(), a.end(),
            make_pair(a[i].first + d, 0)
        );
        if (it == a.end()) {
            // No valid right bank
            continue;
        }
        int j = int(it - a.begin());

        // Candidate sum = best weight in [0..i] + best weight in [j..n-1]
        int sum = pref[i].first + suff[j].first;
        if (sum >= bestSum) {
            bestSum = sum;
            // Store 1-based indices of those banks
            answer = {pref[i].second + 1, suff[j].second + 1};
        }
    }

    // Print result (will be "-1 -1" if answer.first stays -1)
    cout << answer << '\n';
}

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

    read();
    solve();
    return 0;
}
```

4. Python Solution with Detailed Comments  

```python
import sys
import bisect

def main():
    data = sys.stdin.read().strip().split()
    it = iter(data)
    n = int(next(it))
    d = int(next(it))
    # Read banks as (x, w), in sorted order by x
    a = [(int(next(it)), int(next(it))) for _ in range(n)]

    # Build prefix max: pref[i] = (max_w so far, index_of_bank)
    pref = [None] * n
    max_w, max_idx = a[0][1], 0
    pref[0] = (max_w, 0)
    for i in range(1, n):
        w = a[i][1]
        if w > max_w:
            max_w, max_idx = w, i
        pref[i] = (max_w, max_idx)

    # Build suffix max: suff[i] = (max_w from i..n-1, index_of_bank)
    suff = [None] * n
    max_w, max_idx = a[n-1][1], n-1
    suff[n-1] = (max_w, max_idx)
    for i in range(n-2, -1, -1):
        w = a[i][1]
        if w >= max_w:  # >= so later index preferred if equal
            max_w, max_idx = w, i
        suff[i] = (max_w, max_idx)

    # Extract x coordinates for binary search
    xs = [x for x, _ in a]

    best_sum = 0
    ans = (-1, -1)

    # For each left bank i
    for i in range(n):
        xi, wi = a[i]
        target = xi + d
        # Find the first j with xj >= xi + d
        j = bisect.bisect_left(xs, target)
        if j == n:
            continue  # no valid right bank
        # Best left in [0..i], best right in [j..n-1]
        wl, idx_l = pref[i]
        wr, idx_r = suff[j]
        total = wl + wr
        if total >= best_sum:
            best_sum = total
            ans = (idx_l + 1, idx_r + 1)  # convert to 1-based

    print(ans[0], ans[1])

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  
Traverse banks in sorted xi order. Precompute prefix maxima of wi (best left) and suffix maxima of wi (best right). For each bank i as left, binary-search for the earliest j with xj ≥ xi + d. Combine the best prefix up to i and best suffix from j to get a candidate sum. Track the maximum sum and corresponding indices in O(n log n) time.