#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'
using namespace std;
const int maxn = 2e5 + 3;
int n, k;
int a[maxn], b[maxn], t[maxn];
void read()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
for (int i = 1; i <= k; i++)
cin >> t[i];
}
void solve()
{
long long ans = 0;
for (int i = 1; i <= n; i++)
{
vector <int> v;
for (int j = 1; j <= k; j++)
{
if (t[j] >= max(a[i], b[i]))
v.push_back(1);
else
if (t[j] >= min(a[i], b[i]))
v.push_back(2);
}
vector <int> v1;
int cnt = 1;
for (int j = 1; j < (int)v.size(); j++)
{
if (v[j] != v[j-1])
{
if (v[j-1] == 1)
{
if (cnt % 2 == 1)
v1.push_back(1);
}
else
if (v1.empty() || v1.back() == 1)
v1.push_back(2);
cnt = 1;
}
else
cnt++;
}
if (!v.empty())
{
if (v.back() == 1)
{
if (cnt % 2 == 1)
v1.push_back(1);
}
else
if (v1.empty() || v1.back() == 1)
v1.push_back(2);
}
int temp;
if (v1.empty())
temp = 0;
else
if (a[i] >= b[i])
{
if (v1[0] == 1)
temp = (int)v1.size();
else
temp = (int)v1.size()-1;
}
else
{
if (v1[0] == 2)
temp = (int)v.size();
else
{
if ((int)v1.size() == 1)
temp = 1;
else
temp = (int)v1.size()-1;
}
}
if (temp & 1)
ans += b[i];
else
ans += a[i];
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |