- #include <iostream>
- using namespace std;
- int main() {
- //ios::sync_with_stdio(0);
- //cin.tie(0);
- int T, N;
- cin >> T;//幾組測試資料
- while (T--) {
- cin >> N;//一組測試資料,有幾個寶貝球
- int id[N], w[N];//寶貝球的編號和重量
- for (int i = 0; i < N; i++) {
- cin >> id[i];
- }
- for (int j = 0; j < N; j++) {
- cin >> w[j];
- }
- long long ans = 0;
- for (int i =0; i < N-1; i++) {//0 1
- for (int j = i+1; j < N; j++) {//1 2
- if (id[i] > id[j]) {
- ans += w[i] + w[j];
- swap(id[i], id[j]);
- swap(w[i], w[j]);
- }
- }
- }
- cout << ans << "\n";
- }
- return 0;
- }
複製代碼 |