#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<T>,rb_tree_tag,
tree_order_statistics_node_update>;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define all(a) a.begin(),a.end()
const int mxn = 2e5+10;
int arr[mxn][2];
void solve(){
int n,q; cin >> n >> q;
for(int i = 1; i <= n; i++)
cin >> arr[i][0] >> arr[i][1];
for(int i = 1; i <= q; i++){
int k; cin >> k;
for(int j = 1; j <= n; j++)
if(k >= arr[j][0])
swap(arr[j][0],arr[j][1]);
}
ll sum = 0;
for(int i = 1; i <= n; i++)
sum += arr[i][0];
cout << sum;
}
signed main(){
// freopen("cave.in","r",stdin);
// freopen("cave.out","w",stdout);
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |