#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
int n,k;
int a[200005], b[200005], q[200005];
bool flip[200005];
int main(){
scanf("%d %d",&n,&k);
for (int i=0; i<n; i++) {
scanf("%d %d",&a[i],&b[i]);
if(a[i] > b[i]){
swap(a[i],b[i]);
flip[i] = 1;
}
v.push_back(a[i]);
v.push_back(b[i]);
}
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end()) - v.begin());
for (int i=0; i<n; i++) {
a[i] = (int)(lower_bound(v.begin(),v.end(),a[i]) - v.begin());
b[i] = (int)(lower_bound(v.begin(),v.end(),b[i]) - v.begin());
}
for (int i=0; i<k; i++) {
scanf("%d",&q[i]);
q[i] = (int)(upper_bound(v.begin(),v.end(),q[i]) - v.begin()) - 1;
}
for (int i=0; i<k; i++) {
for (int j=0; j<n; j++) {
if(b[j] >= q[i]){
flip[j] ^= 1;
}
else if(a[j] >= q[i]){
flip[j] = 1;
}
}
}
long long ret = 0;
for (int i=0; i<n; i++) {
if(flip[i]) ret += v[b[i]];
else ret += v[a[i]];
}
printf("%lld",ret);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
4120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
4252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2000 ms |
4248 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |