This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |