#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> parking;
vector<int> weights;
weights.push_back(0);
int ans = 0;
set<int> rem;
parking.push_back(0);
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
parking.push_back(temp);
rem.insert(i + 1);
}
for (int i = 0; i < m; i++) {
int temp;
cin >> temp;
weights.push_back(temp);
}
map<int, int> pos;
queue<int> toPlace;
for (int i = 0; i < 2 * m; i++) {
int temp;
cin >> temp;
if (temp < 0) {
temp *= -1;
rem.insert(pos[temp]);
}
else {
toPlace.push(temp);
}
while (rem.size() > 0 && toPlace.size() > 0) {
pos[toPlace.front()] = *rem.begin();
ans += weights[toPlace.front()] * parking[*rem.begin()];
rem.erase(rem.begin());
toPlace.pop();
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |