#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
int main()
{
int N,M;
std::cin >> N >> M;
std::vector<int> rate(N);
for(auto& i : rate) std::cin >> i;
std::vector<int> weight(M);
for(auto& i : weight) std::cin >> i;
weight.emplace(weight.begin()); // 1-indexing
std::vector<int> spaces;
for(int i = 0; i < N; i++) spaces.push_back(i);
std::queue<int> q;
std::vector<int> space(M+1);
long long c = 0;
for(int i = 0; i < 2*M; i++)
{
int op;
std::cin >> op;
if(op > 0)
q.push(op);
else
spaces.push_back(space[-op]);
while(q.size() && spaces.size())
{
auto car = q.front(); q.pop();
auto p = std::min_element(spaces.begin(),spaces.end());
auto sp = *p; spaces.erase(p);
space[car] = sp;
c += weight[car] * rate[sp];
}
}
std::cout << c << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
424 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
424 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |