#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);
}
int diff = 1;
for (int j = 0; j < (int)v.size()-1; j++)
if (v[j] != v[j+1])
diff++;
int cnt = 0;
for (auto j: v)
{
if (j == 2)
break;
cnt++;
}
int first;
if (cnt % 2 == 0)
{
if (cnt != 0)
diff--;
first = 2;
}
else
first = 1;
int temp;
if (diff == 0)
temp = 0;
else
if (a[i] >= b[i])
{
if (first == 1)
temp = diff;
else
temp = diff + 1;
}
else
{
if (first == 2)
temp = diff;
else
temp = max(1, diff - 1);
}
// cout << i << " " << temp << endl;
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 |
- |