#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
vector<pair<ll, ll>> nums;
vector<ll> q;
int n, m;
pair<int, int> check(int l, int r, ll a, ll b) {
if (l == r) {
int n1 = 0, n2 = 0;
if (q[l] >= a) {
n1 = 2;
}
else {
n1 = 1;
}
if (q[l] >= b) {
n2 = 1;
}
else {
n2 = 2;
}
return { n1, n2 };
}
int mid = (l + r) / 2;
pair<int, int> p1 = check(l, mid, a, b);
pair<int, int> p2 = check(mid + 1, r, a, b);
int n1 = 0, n2 = 0;
if (p1.first == 1) {
n1 = p2.first;
}
else {
n1 = p2.second;
}
if (p2.first == 1) {
n2 = p2.first;
}
else {
n2 = p2.second;
}
return { n1, n2 };
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
nums.push_back({ a, b });
}
for (int i = 0; i < m; i++) {
ll temp;
cin >> temp;
q.push_back(temp);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
pair<int, int> p = check(0, m - 1, nums[i].first, nums[i].second);
if (p.first == 1) {
ans += nums[i].first;
}
else {
ans += nums[i].second;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |