# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
493851 | ahmeteren | Garage (IOI09_garage) | C++17 | 37 ms | 65540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ll n, m;
cin >> n >> m;
vector<ll> c(n + 1), w(m + 1);
for(int i = 1; i <= n; i++)
cin >> c[i];
for(int i = 1; i <= m; i++)
cin >> w[i];
ll cevap = 0;
map<ll, ll> mp;
set<ll> st;
queue<ll> q;
for(int i = 1; i <= n; i++)
st.insert(i);
for(int i = 0; i < 2 * m; i++)
{
int x;
cin >> x;
if(x > 0)
{
if(st.size())
{
ll a = *st.begin();
cevap += w[x] * c[a];
mp[x] = a;
st.erase(st.begin());
}
else
{
q.push(x);
}
}
else
{
x = -x;
st.insert(mp[x]);
if(q.size())
{
ll a = q.front(), b = *st.begin();
q.pop();
mp[a] = b;
cevap += w[a] * c[b];
st.erase(st.begin());
}
}
}
cout << cevap << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |