#include <bits/stdc++.h>
#define fi first
#define se second
#define NAME "wiring"
using namespace std;
typedef long long LL;
typedef pair <int, int> pii;
typedef double DB;
typedef pair <LL, LL> pLL;
const int NMAX = 1e6+7;
int n, m;
LL min_total_length(vector <int> r, vector <int> b) {
LL res = 0;
n = r.size();
m = b.size();
if(r[n-1] < b[0]) {
for(int i = 0; i < n; ++i)
res += abs(b[0] - r[i]);
for(int i = 1; i < m; ++i)
res += abs(b[[i] - r[n-1]);
res -= abs(b[0] - r[n-1]);
return res;
}
vector <pii> a;
for(int i = 0; i < n; ++i) {
a.push_back(pii(r[i], 0));
}
for(int i = 0; i < m; ++i) {
a.push_back(pii(b[i], 1));
}
int nm = n + m;
sort(a.begin(), a.end());
int i = 0, j = 0, ck = 0;
while(i < nm) {
while(j+1 < nm && a[j+1].se == a[i].se) j++;
int pos1, pos2;
if(i > 0) pos1 = a[i-1].fi;
else pos1 = INT_MAX;
if(j < nm-1) pos2 = a[j+1].fi;
else pos2 = INT_MAX;
for(int t = i; t <= j; ++t)
res += min(abs(pos1 - a[t].fi), abs(pos2 - a[t].fi));
if(i > 0 && ck == 1)
res -= abs(pos1 - a[i].fi);
if(abs(pos1 - a[j].fi) > abs(pos2 - a[j].fi)) ck = 1;
else ck = 0;
j++; i = j;
}
return res;
}
vector <int> ver, veb;
Compilation message
wiring.cpp: In function 'LL min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:22:25: error: two consecutive '[' shall only introduce an attribute before '[' token
res += abs(b[[i] - r[n-1]);
^