doubledist(int x1, int y1, int x2, int y2){ returnsqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
intmain(void) { int t; cin >> t; while (t--) { int m, l; cin >> m >> l; vector<vector<int>> g(m, vector<int>(m)); for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ++j) { cin >> g[i][j]; } }
int x, y; cin >> x >> y; int ans = -1; while (l != ans) { ans = l; for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ++j) { if (g[i][j] > 0 && dist(x, y, i, j) <= l) { l += g[i][j]; g[i][j] = -1; } } } } cout << ans << endl; } return0; }
intmain(void) { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n);
unordered_map<int, int> w(n);
for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> b(a); for (int i = 0; i < n; ++i) { cin >> w[a[i]]; } int ans = INT_MAX;
sort(a.begin(), a.end()); do { bool flag = true; for (int i = 0; i < n; ++i) { if (a[i] == b[i]) { flag = false; break; } } if (flag) { int cur = 0; for (int i = 0; i < n; ++i) { int tmp = find(a.begin(), a.end(), b[i]) - a.begin() - i; cur += w[b[i]] * abs(tmp); } ans = min(ans, cur); } } while (next_permutation(a.begin(), a.end()));
intmain(void) { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); vector<int> w(n);
for (int i = 0; i < n; ++i) { cin >> a[i]; } int sum = 0; for (int i = 0; i < n; ++i) { cin >> w[i]; sum += w[i]; } if (n & 1) { int minIdx = 0; for (int i = 0; i < n; i += 2) { if (w[i] < w[minIdx]) { minIdx = i; } } sum += w[minIdx]; }