#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 2e5 + 25;
const int K = 2e5 + 25;
int n,k,a[N],b[N],t[N];
namespace sub1
{
bool check()
{
return (n<=1000 && k<=1000);
}
void solve()
{
for (int tri=1; tri<=k; ++tri)
{
int cur=t[tri];
for (int i=1; i<=n; ++i) if (a[i]<=cur) swap(a[i],b[i]);
}
ll sum=0;
for (int i=1; i<=n; ++i) sum+=a[i];
cout<<sum;
}
}
void solve()
{
cin>>n>>k;
for (int i=1; i<=n; ++i) cin>>a[i]>>b[i];
for (int i=1; i<=k; ++i) cin>>t[i];
if (sub1::check()) return void(sub1::solve());
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
int testcase=1;
// cin>>testcase;
while (testcase--)
solve();
// #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
// cerr << "Time elapsed: " << TIME << " s.\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... |