#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+100;
pair<int,int> a[N];
int n,k;
// struct {
// int mxa,mxb;
// bool lazy=0;
// }seg[N*4];
// // we will flip a range iff mx<=t then lazy^=1
// // else We push the lazy downward
// void push(int v)
// {
// int lc=2*v,rc=lc+1;
// if(seg[v].lazy)
// {
// seg[v].lazy=0;
// swap(seg[v].mxa,seg[v].mxb);
// seg[lc].lazy=!seg[lc].lazy;
// seg[rc].lazy=!seg[rc].lazy;
// }
// }
// void Build(int l=1,int r=n,int v=1)
// {
// if(l==r)
// {
// seg[v].mxa=a[l].first;
// seg[v].mxb=a[l].second;
// return;
// }
// int m=(l+r)/2;
// int lc=2*v,rc=lc+1;
// Build(l,m,lc);
// Build(m+1,r,rc);
// seg[v].mxa=max(seg[lc].mxa,seg[rc].mxa);
// seg[v].mxb=max(seg[lc].mxb,seg[rc].mxb);
// }
// void Update(int&t,int l=1,int r=n,int v=1)
// {
// push(v);
// if(seg[v].mxa<=t)
// {
// seg[v].lazy=!seg[v].lazy;
// push(v);
// return;
// }
// if(l==r)return;
// int m=(l+r)/2,lc=2*v,rc=lc+1;
// Update(t,l,m,lc);
// Update(t,m+1,r,rc);
// seg[v].mxa=max(seg[lc].mxa,seg[rc].mxa);
// seg[v].mxb=max(seg[lc].mxb,seg[rc].mxb);
// }
// ll ans=0;
// void Answer(int l=1,int r=n,int v=1)
// {
// push(v);
// if(l==r)
// {
// ans+=seg[v].mxa;
// return;
// }
// int m=(l+r)/2;
// int lc=2*v,rc=lc+1;
// Answer(l,m,lc);
// Answer(m+1,r,rc);
// }
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll ans=0;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i].first>>a[i].second;
}
sort(a+1,a+n+1);
// Build();
a[n+1]=a[n+2]=a[n+3]=a[n+4]={2e9,2e9};
a[n+4+1]=a[n+4+2]=a[n+4+3]=a[n+4+4]={2e9,2e9};
for(int i=1;i<=k;i++)
{
int t;
cin>>t;
for(int l=1;l<=n;l+=8)
{
if(a[l].first<=t)
{
swap(a[l].first,a[l].second);
}
if(a[l+1].first<=t)
{
swap(a[l+1].first,a[l+1].second);
}
if(a[l+2].first<=t)
{
swap(a[l+2].first,a[l+2].second);
}
if(a[l+3].first<=t)
{
swap(a[l+3].first,a[l+3].second);
}
if(a[l+4].first<=t)
{
swap(a[l+4].first,a[l+4].second);
}
if(a[l+5].first<=t)
{
swap(a[l+5].first,a[l+5].second);
}
if(a[l+6].first<=t)
{
swap(a[l+6].first,a[l+6].second);
}
if(a[l+7].first<=t)
{
swap(a[l+7].first,a[l+7].second);
}
}
// Update(t);
}
for(int i=1;i<=n;i++)ans+=a[i].first;
// Answer();
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... |