#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int32_t MAX_N = 100;
const int32_t MAX_M = 2000;
int32_t rates[MAX_N + 5], weights[MAX_M + 5], placeOf[MAX_M + 5];
set< int32_t > emptyPlaces;
queue< int32_t > waitingCars;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int32_t n, m;
cin >> n >> m;
for(int32_t i = 0; i < n; i++) {
cin >> rates[i];
emptyPlaces.insert(i);
}
for(int32_t i = 0; i < m; i++) {
cin >> weights[i];
}
int32_t ans = 0;
for(int32_t i = 0; i < 2 * m; i++) {
int32_t ind;
cin >> ind;
if(ind < 0) {
ind = -ind;
emptyPlaces.insert(placeOf[ind]);
if(!waitingCars.empty()) {
int32_t ind = waitingCars.front();
waitingCars.pop();
placeOf[ind] = *emptyPlaces.begin();
emptyPlaces.erase(emptyPlaces.begin());
ans += rates[placeOf[ind]] * weights[ind - 1];
}
}
else {
if(!emptyPlaces.empty()) {
placeOf[ind] = *emptyPlaces.begin();
emptyPlaces.erase(emptyPlaces.begin());
ans += rates[placeOf[ind]] * weights[ind - 1];
}
else {
waitingCars.push(ind);
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Correct |
2 ms |
616 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
2 ms |
720 KB |
Output is correct |
13 |
Correct |
3 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
3 ms |
720 KB |
Output is correct |
17 |
Correct |
4 ms |
736 KB |
Output is correct |
18 |
Correct |
3 ms |
772 KB |
Output is correct |
19 |
Correct |
3 ms |
816 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |