#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<int> 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 (p1.second == 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++) {
int temp;
cin >> temp;
q.push_back(temp);
}
ll ans = 0;
cout << endl << endl << endl;
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;
//cout << nums[i].first << endl;
}
else {
ans += nums[i].second;
//cout << nums[i].second << endl;
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
12 ms |
364 KB |
Output is correct |
9 |
Correct |
10 ms |
364 KB |
Output is correct |
10 |
Correct |
10 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
236 KB |
Output is correct |
13 |
Correct |
11 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
12 ms |
364 KB |
Output is correct |
9 |
Correct |
10 ms |
364 KB |
Output is correct |
10 |
Correct |
10 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
236 KB |
Output is correct |
13 |
Correct |
11 ms |
364 KB |
Output is correct |
14 |
Correct |
895 ms |
1004 KB |
Output is correct |
15 |
Execution timed out |
3044 ms |
1512 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
11 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
11 ms |
364 KB |
Output is correct |
8 |
Correct |
12 ms |
364 KB |
Output is correct |
9 |
Correct |
10 ms |
364 KB |
Output is correct |
10 |
Correct |
10 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
236 KB |
Output is correct |
13 |
Correct |
11 ms |
364 KB |
Output is correct |
14 |
Correct |
895 ms |
1004 KB |
Output is correct |
15 |
Execution timed out |
3044 ms |
1512 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |