# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1082754 | toast12 | Garage (IOI09_garage) | C++14 | 4 ms | 456 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> rates(n), weights(m);
for (int i = 0; i < n; i++) {
cin >> rates[i];
}
for (int i = 0; i < m; i++) {
cin >> weights[i];
}
multiset<int> available;
for (int i = 0; i < n; i++) {
available.insert(i);
}
map<int, int> lots;
queue<int> q;
long long ans = 0;
for (int i = 0; i < 2*m; i++) {
int car;
cin >> car;
if (car < 0) {
car *= -1;
car--;
if (!q.empty()) {
int car2 = q.front();
lots[car2] = lots[car];
ans += weights[car2]*rates[lots[car2]];
q.pop();
}
else {
available.insert(lots[car]);
}
lots[car] = 0;
continue;
}
car--;
if (available.empty()) {
q.push(car);
continue;
}
int lot = *(available.begin());
ans += weights[car]*rates[lot];
lots[car] = lot;
available.erase(lot);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |