# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
957523 | hirayuu_oj | Garage (IOI09_garage) | C++17 | 1 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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... |