# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
372861 | lakshith_ | Garage (IOI09_garage) | C++14 | 3 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>
#define ll long long
using namespace std;
int main(){
int n,m;
cin >> n >> m;
int r[n],w[m];
for(int i=0;i<n;i++)cin >> r[i];
for(int i=0;i<m;i++)cin >> w[i];
ll ans = 0;
int space[n];
memset(space,-1,sizeof(space));
queue<int> q;
for(int i=0;i<2*m;i++){
int a;
cin >> a;
if(a<0){
a*=-1;
a--;
int index = 0;
for(int j=0;j<n;j++)if(space[j]==a)index = j;
space[index]=-1;
}else{
a--;
q.push(a);
}
if(q.empty())continue;
int index = -1;
for(int j=0;j<n;j++)
if(space[j]==-1){
index =j;
break;
}
if(index!=-1){
//cout << index+1 << "\t" << q.front()+1 << "\n";
space[index]=q.front();
ans += r[index]*w[q.front()];
q.pop();
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |