#include <bits/stdc++.h>
#define int int64_t
signed main() {
int n, q;
std::cin >> n >> q;
std::vector<int> a(n + 1), b(n + 1);
for(int i = 1; i <= n; i++) {
std::cin >> a[i] >> b[i];
}
std::vector<int> x(q + 1);
for(int i = 1; i <= q; i++) {
std::cin >> x[i];
}
std::vector<int> t(n + 1);
for(int i = 1; i <= n; i++) {
if(a[i] > b[i]) {
t[i] = 1;
std::swap(a[i], b[i]);
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= q; j++) {
if(x[j] >= b[i]) {
t[i] ^= 1;
}
else if(x[j] >= a[i]) {
t[i] = 1;
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += (t[i] == 0 ? a[i] : b[i]);
}
std::cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |