PAT 1037 Magic Coupon

时间:2021-09-18 12:52:16
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm> using namespace std; void print(vector<int> &v) {
int len = v.size();
for (int i=; i<len; i++) {
printf(" %d", v[i]);
}
printf("\n");
} int main() {
int NC, NP;
scanf("%d", &NC);
vector<int> C(NC); for (int i=; i<NC; i++) {
scanf("%d", &C[i]);
} scanf("%d", &NP);
vector<int> P(NP);
for (int i=; i<NP; i++) {
scanf("%d", &P[i]);
} sort(C.begin(), C.end(), greater<int>());
sort(P.begin(), P.end(), greater<int>()); int clen = C.size();
int plen = P.size(); int ci = ;
int pi = ;
int dc, dp;
long long sum = ; while (ci < clen && pi < plen && (dc=C[ci]) > && (dp=P[pi]) > ) {
sum += dc * dp;
ci++, pi++;
} ci = clen - ;
pi = plen - ; while (ci >= && pi >= && (dc=C[ci]) < && (dp=P[pi]) < ) {
sum += dc * dp;
ci--, pi--;
}
printf("%lld", sum);
return ;
}

有个case 30+ms是不是方法错了?