Skip to content

Instantly share code, notes, and snippets.

@AntonieValentin
Created April 14, 2022 18:44
Show Gist options
  • Save AntonieValentin/1aa3966cdad412dbbccda062a076b074 to your computer and use it in GitHub Desktop.
Save AntonieValentin/1aa3966cdad412dbbccda062a076b074 to your computer and use it in GitHub Desktop.
IOI 2009, Day 1, Garage
#include <bits/stdc++.h>
using namespace std;
int n,mr,i,x,m[2001],j,ok,indice;
queue <int> Q;
long long suma;
pair<int,int> v[101];
int main()
{
cin>>n>>mr;
for(i=1;i<=n;i++)
cin>>v[i].first;
for(i=1;i<=mr;i++)
cin>>m[i];
for(i=1;i<=2*mr;i++){
cin>>x;
if(x > 0){
ok = 0;
for(j=1;j<=n;j++){
if(!v[j].second){
suma += 1LL * m[x] * v[j].first;
v[j].second = x;
ok = 1;
break;
}
}
if(!ok)
Q.push(x);
}
else{
indice = 0;
for(j=1;j<=n;j++){
if(v[j].second == -x){
indice = j;
v[j].second = 0;
break;
}
}
if(Q.empty()==false){
suma += 1LL * m[Q.front()] * v[indice].first;
v[indice].second = Q.front();
Q.pop();
}
}
}
cout << suma;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment