# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309472 | cig32 | Garage (IOI09_garage) | C++14 | 4 ms | 384 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;
bool tiAs(bool available[], int N){
for(int i=0;i<N;i++){
if(available[i]==true){
return true;
}
}
return false;
}
int bS(bool available[], int N){
for(int i=0;i<N;i++){
if(available[i]==true){
return i;
}
}
}
int main(){
int N,M;
cin >> N >> M;
int r[N],w[M];
bool available[N];
int space[M];
for(int i=0;i<N;i++){
cin >> r[i];
available[i]=true;
}
for(int i=0;i<M;i++){
cin >> w[i];
}
int ans=0;
queue<int> waiting;
for(int i=0;i<2*M;i++){
int input;
cin >> input;
if(input>0){
if(tiAs(available,N)==true){
int t=bS(available,N);
available[t]=false;
space[input-1]=t;
int a=w[input-1]*r[t];
ans+=a;
}
else{
waiting.push(input);
}
}
else{
available[space[abs(input)-1]]=true;
if(waiting.size()!=0){
available[space[abs(input)-1]]=false;
space[waiting.front()-1]=space[abs(input)-1];
int a=w[waiting.front()-1]*r[space[abs(input)-1]];
waiting.pop();
ans+=a;
}
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |