# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
248772 | uacoder123 | Garage (IOI09_garage) | C++14 | 1 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1;
for(;test>0;--test)
{
int n,m,ans=0;
cin>>n>>m;
int r[n+1],w[m+1],pos[m+1]={};
set<int>p;
queue<int> q;
for(int i=1;i<=n;++i)
{
cin>>r[i];
p.insert(i);
}
for(int i=1;i<=m;++i)
cin>>w[i];
for(int i=0;i<2*m;++i)
{
int f;
cin>>f;
if(f>0)
{
if(p.size()>0)
{
int fp=(*p.begin());
p.erase(p.begin());
pos[f]=fp;
ans+=r[fp]*w[f];
}
else
q.push(f);
}
else
{
p.insert(pos[-f]);
pos[-f]=0;
if(q.size())
{
int fi=q.front();
q.pop();
int fp=(*p.begin());
p.erase(p.begin());
pos[fi]=fp;
ans+=r[fp]*w[fi];
}
}
}
cout<<ans<<endl;
}
return(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |