# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
462908 | danielsuh | Garage (IOI09_garage) | C++17 | 3 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, M; cin >> N >> M;
vector<int> prices(N + 1), cars(M + 1);
for(int i = 1; i <= N; i++) cin >> prices[i];
for(int i = 1; i <= M; i++) cin >> cars[i];
set<int> free;
for(int i = 1; i <= N; i++) {
free.insert(i);
}
deque<int> line;
map<int, int> spots;
int ans = 0;
for(int i = 0; i < 2 * M; i++) {
int step; cin >> step;
if(step > 0) {
if(free.empty()) {
line.push_back(step);
continue;
}
assert(!free.empty());
int space = *free.begin();
free.erase(*free.begin());
ans += cars[step] * prices[space];
spots[step] = space;
}else {
free.insert(spots[-step]);
if(!line.empty()) {
int car = *line.begin();
ans += cars[car] * prices[spots[-step]];
line.pop_front();
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |