# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1119750 | kasdo | Garage (IOI09_garage) | C++14 | 4 ms | 596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int n, m;
cin>>n>>m;
int a[n + 5], b[m + 5];
priority_queue<int> q;
for(int i=1; i<=n; i++)
{
cin>>a[i];
q.push(-i);
}
for(int i=1; i<=m; i++) cin>>b[i];
int park[m + 5];
vector<int> proc;
int ans = 0;
for(int i=1; i<=2*m; i++)
{
int x;
cin>>x;
if (x > 0) // join
{
if (q.size() > 0) // there is a parking
{
int cur = q.top();
cur *= -1;
park[x] = cur;
ans += a[cur] * b[x];
q.pop();
}
else // there is no parking
{
proc.push_back(x);
}
}
else
{
q.push(-park[-x]);
bool f = 0;
if (q.size() > 0 && proc.size() > 0)
{
f = 1;
reverse(proc.begin(), proc.end());
}
while(q.size() > 0 && proc.size() > 0)
{
int cur = q.top();
cur *= -1;
int idx = proc.back();
// park[idx] = cur;
ans += a[cur] * b[idx];
q.pop();
proc.pop_back();
}
if (f && proc.size() > 0) reverse(proc.begin(), proc.end());
}
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |