1 条题解
-
0
#include #include #include using namespace std;
typedef long long ll;
int main() { int N, M, P; cin >> N >> M >> P;
vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int> B(M); for (int i = 0; i < M; i++) { cin >> B[i]; } // 对 B 排序并计算前缀和 sort(B.begin(), B.end()); vector<ll> pref(M + 1, 0); for (int i = 0; i < M; i++) { pref[i + 1] = pref[i] + B[i]; } ll total = 0; for (int i = 0; i < N; i++) { int threshold = P - A[i]; // 找到第一个 >= threshold 的位置 int pos = lower_bound(B.begin(), B.end(), threshold) - B.begin(); // 第一类:B_j < threshold ll cnt1 = pos; total += cnt1 * A[i] + pref[pos]; // 第二类:B_j >= threshold ll cnt2 = M - pos; total += cnt2 * P; } cout << total << endl; return 0;}
- 1
信息
- ID
- 14544
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 3
- 已通过
- 2
- 上传者