#include <bits/stdc++.h>
using namespace std;
int n,m;
int rates[102];
int weights[2002];
int estacionamiento[102];
queue<int> fila;
int ans,num;
int busca_esp(int x){
for(int i=1;i<=n;i++){
if(estacionamiento[i]==x){
return i;
}
}
return -1;
}
void colocar(int carro, int espacio){
estacionamiento[espacio]=carro;
ans+=rates[espacio]*weights[carro];
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>rates[i];
}
for(int i=1;i<=m;i++){
cin>>weights[i];
}
for(int i=1;i<=2*m;i++){
cin>>num;
if(num<0){
//sacas carro
int espacio=busca_esp(num*-1);
estacionamiento[espacio]=0;
if(!fila.empty()){
colocar(fila.front(),espacio);
fila.pop();
}
}else{
//metes carro, sino hay lugar lo metes en la fila
int espacio=busca_esp(0);
if(espacio==-1){
fila.push(num);
}else{
colocar(num,espacio);
}
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |