Editorial for Gộp Máy Chủ


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
// This solution is from the old statement,
// where n is not required to be even and there are 2n servers
// Quick fix is to just half n uppon reading n.

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

void solve() {
    int n, k;
    cin >> n >> k;
    n /= 2;

    vector<int> a(2*n);
    for(int i = 0; i < 2*n; ++i) {
        cin >> a[i];
    }

    int minD = (a[2*n-1] + a[2*n-1 - k]) - (a[0] + a[k]);
    printf("%d\n", minD);

    vector<pii> ans;
    for(int i = 0; i < k; ++i) {
        ans.emplace_back(i, i + k);
    }
    for(int i = 2*n-k; i < 2*n; ++i) {
        ans.emplace_back(i - k, i);
    }
    for(int i = 2*k; i < 2*n-2*k; i += 2) {
        ans.emplace_back(i, i + 1);
    }

    for(auto [x, y]: ans) {
        printf("%d %d\n", x+1, y+1);
    }
}

int main() {
    int t; cin >> t;
    while (t--) solve();

    return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.