# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
957523 | hirayuu_oj | Garage (IOI09_garage) | C++17 | 1 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N,M;
cin>>N>>M;
vector<ll> R(N);
rep(i,N){
cin>>R[i];
}
vector<ll> W(M);
rep(i,M){
cin>>W[i];
}
vector<ll> use(N,-1);
queue<ll> wait;
ll ans=0;
rep(i,2*M){
ll t;
cin>>t;
if(t>0){
t--;
rep(j,N){
if(use[j]==-1){
use[j]=t;
ans+=W[t]*R[j];
t=-1;
break;
}
}
if(t!=-1){
wait.push(t);
}
}
else{
t=-1-t;
rep(j,N){
if(use[j]==t){
use[j]=-1;
if(!wait.empty()){
use[j]=wait.front();
ans+=W[wait.front()]*R[j];
wait.pop();
}
break;
}
}
}
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |