我的代码
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int s1, s2, s3, s4;
cin >> s1 >> s2 >> s3 >> s4;
int A[20], B[20], C[20], D[20];
for (int i = 0; i < s1; i++) {
cin >> A[i];
}
for (int i = 0; i < s2; i++) {
cin >> B[i];
}
for (int i = 0; i < s3; i++) {
cin >> C[i];
}
for (int i = 0; i < s4; i++) {
cin >> D[i];
}
int subjects[4][20];
int num[4] = {s1, s2, s3, s4};
for (int i = 0; i < 4; i++) {
if (i == 0) {
for (int j = 0; j < s1; j++){
subjects[i][j] = A[j];
}
}
else if (i == 1) {
for (int j = 0; j < s2; j++){
subjects[i][j] = B[j];
}
}
else if (i == 2) {
for (int j = 0; j < s3; j++){
subjects[i][j] = C[j];
}
} else {
for (int j = 0; j < s4; j++){
subjects[i][j] = D[j];
}
}
}
int totalTime = 0;
for (int i = 0; i < 4; i++) {
int n = num[i];
sort(subjects[i], subjects[i] + n, greater<int>());
int time = 0;
for (int j = 0; j < n / 2; j++) {
time = max(time, subjects[i][2 * j] + subjects[i][2 * j + 1]);
}
if (n % 2 == 1) {
time += subjects[i][n - 1];
}
totalTime += time;
}
cout << totalTime << endl;
return 0;
}
这是一个爆零代码,求助!!!