#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n, k;
cin >> n >> k;
pair<int, int> arr[n];
for(int i = 0; i < n ; i++) cin >> arr[i].first >> arr[i].second;
bool vals[n];
memset(vals, false, sizeof(vals));
for(int i = 0; i < k;i ++) {
int a;
cin >> a;
for(int j =0; j < n; j++) {
if(vals[j] && arr[j].second <= a) vals[j] = false;
else if(!vals[j] && arr[j].first <= a) vals[j] = true;
}
}
int total = 0;
for(int i = 0; i < n; i++) {
if(vals[i]) total += arr[i].second;
else total += arr[i].first;
}
cout<<total<<'\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |