# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
535391 | devariaota | Garage (IOI09_garage) | C++17 | 2 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, m;
int rate[105];
int weight[2005];
int loc[2005];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> rate[i];
}
for(int i = 1; i <= m; i++) {
cin >> weight[i];
}
priority_queue<int, vector<int>, greater<int> > pq;
for(int i = 1; i <= n; i++) {
pq.push(i);
}
int ans = 0;
queue<int> q;
for(int i = 1; i <= 2 * m; i++) {
int a;
cin >> a;
if (a > 0) {
if (!pq.empty()) {
loc[a] = pq.top();
ans += weight[a] * rate[loc[a]];
pq.pop();
}
else {
q.push(a);
}
}
else {
a *= -1;
if (!q.empty()) {
int next = q.front();
q.pop();
ans += weight[next] * rate[loc[a]];
}
else {
pq.push(loc[a]);
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |