#include <bits/stdc++.h>
using namespace std;
const long long MX=2e5+10;
long long msq[MX],w[MX],cs[MX],ans=0;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
priority_queue < pair < long long , long long > , vector < pair < long long , long long > > , greater < pair < long long , long long > > > qp;
long long n,m;
cin>>n>>m;
for(long long i=1;i<=n;i++)
{
cin>>cs[i];
qp.push({i,cs[i]});
}
for(long long i=1;i<=m;i++)
{
cin>>w[i];
}
queue < long long > qm;
for(long long i=1;i<=2*m;i++)
{
long long a;
cin>>a;
if(a>0)
{
qm.push(a);
}
else
{
a=(-a);
qp.push({msq[a],cs[msq[a]]});
msq[a]=0;
}
while(!qp.empty() && !qm.empty())
{
long long o1=qp.top().first;
qp.pop();
long long o2=qm.front();
qm.pop();
ans+=w[o2]*cs[o1];
msq[o2]=o1;
}
}
cout<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4560 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |