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) 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. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

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

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

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;

void read() {
    cin >> n >> d;
    a.resize(n);
    cin >> a;
}

void solve() {
    // Banks come sorted by coordinate x. We pick the left bank i and the right
    // bank j with x[j] - x[i] >= d. For a fixed split point the best left bank
    // is the richest among coordinates <= some value and the best right bank
    // the richest among coordinates >= some value, so we precompute prefix and
    // suffix maxima of (money, index): pref[i] is the richest bank in [0, i],
    // suff[j] the richest in [j, n - 1]. For each i we binary-search the first
    // index j whose coordinate is at least x[i] + d, then pref[i] + suff[j] is
    // a candidate total. We keep the pair achieving the maximum, defaulting to
    // -1 -1 when no valid j exists for any i.

    vector<pair<int, int>> pref(n), suff(n);
    for(int i = 0; i < n; i++) {
        pref[i] = {a[i].second, i};
        if(i > 0) {
            pref[i] = max(pref[i], pref[i - 1]);
        }
    }

    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 ans = 0;
    pair<int, int> ans_pos = {-1, -1};

    for(int i = 0; i < n; i++) {
        auto it = lower_bound(a.begin(), a.end(), make_pair(a[i].first + d, 0));
        if(it == a.end()) {
            continue;
        }

        int j = it - a.begin();
        int cand = pref[i].first + suff[j].first;
        if(cand >= ans) {
            ans = cand;
            ans_pos = {pref[i].second + 1, suff[j].second + 1};
        }
    }

    cout << ans_pos << '\n';
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        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.
