#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// #endif
ll n, m;
cin >> n >> m;
vector<ll> c(n + 1), w(m + 1);
for(int i = 1; i <= n; i++)
cin >> c[i];
for(int i = 1; i <= m; i++)
cin >> w[i];
ll cevap = 0;
map<ll, ll> mp;
set<ll> st;
queue<ll> q;
for(int i = 1; i <= n; i++)
st.insert(i);
for(int i = 0; i < 2 * m; i++)
{
int x;
cin >> x;
if(x > 0)
{
if(st.size())
{
ll a = *st.begin();
cevap += w[x] * c[a];
mp[x] = a;
st.erase(st.begin());
}
else
{
q.push(x);
}
}
else
{
x = -x;
st.insert(mp[x]);
if(q.size())
{
ll a = q.front(), b = *st.begin();
q.pop();
mp[a] = b;
cevap += w[a] * c[b];
st.erase(st.begin());
}
}
}
cout << cevap << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
352 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
2 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |