// zoltan chivay // marigold // triss #include #include //#include using namespace std; int min (int a, int b) { return a < b ? a : b; } void printTable (int * table, int s) { for (int y = 0; y < s; y++) { for (int x = 0; x < s; x++) { cout << table[s*y + x] << " "; } cout << endl; } } int getMax (int * pole, int size) { int max = pole[0], maxIndex = 0; for (int i = 0; i < size; i++ ) { if (pole[i] > max) { max= pole[i]; maxIndex = i; } } pole[maxIndex] = -1; return max; } int sort (const void * a, const void * b) { int* arg1 = (int*) a; int* arg2 = (int*) b; if (*arg1 < *arg2) return -1; else if (*arg1 == *arg2) return 0; else return 1; } int main (int argc, char ** argv) { int n; cin >> n; for (int i = 0; i < n; i++) { int s; cin >> s; //cout << "s = " << s << endl; int * pX = new int [s]; int * pY = new int [s]; for (int j = 0; j < s; j++) { cin >> pX[j]; } for (int j = 0; j < s; j++) { cin >> pY[j]; } // compute max int max = 0; for (int x = 0; x < s; x++) for (int y = 0; y < s; y++) { max += min (pX[x], pY[y]); } // compute min int xmin = 0; if (s == 1) xmin = (pX[i] >= pY[i]) ? pX[0] : pY[0]; else { //qsort (pX, s, sizeof(int), sort); //qsort (pY, s, sizeof(int), sort); for (int i = 0; i < s; i++) { int maxX = getMax(pX, s); int maxY = getMax(pY, s); xmin += (maxX >= maxY) ? maxX : maxY; // xmin += pX[i] >= pY[i] ? pX[i] : pY[i]; //cout << "xmin += " << (pX[i] >= pY[i] ? pX[i] : pY[i]) << endl; } } cout << "Minimalni budova obsahuje " << xmin << " kostek, maximalni " << max << " kostek." << endl; } return 0; }