Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<queue>
- using namespace std;
- typedef struct{
- int cost;
- int car;
- }garage;
- int main()
- {
- int n,m;
- scanf("%d %d",&n,&m);
- garage gar[n];
- int coempty = n;
- for(int i=0;i<n;i++){
- scanf("%d",&gar[i].cost);
- gar[i].car = 0;
- }
- int weight[m];for(int i=0;i<m;i++)scanf("%d",&weight[i]);
- int table[2*m];
- int ans = 0;
- queue<int> queue;
- for(int i=0;i<2*m;i++){
- scanf("%d",&table[i]);
- if(table[i] > 0){ // car in
- if(coempty > 0){// empty
- for(int j=0;j<n;j++){
- if(gar[j].car == 0){
- gar[j].car = table[i];
- ans += gar[j].cost * weight[gar[j].car-1];
- coempty--;
- break;
- }
- }
- }else{ // not empty
- queue.push(table[i]);
- }
- }
- else if(table[i] < 0){ // car out
- for(int j=0;j<n;j++){
- if(gar[j].car == -1*table[i]){
- gar[j].car = 0;
- coempty++;
- break;
- }
- }
- if(!queue.empty()){ //cars are queued
- for(int j=0;j<n;j++){
- if(gar[j].car == 0){
- gar[j].car = queue.front();
- ans += gar[j].cost * weight[gar[j].car-1];
- queue.pop();
- coempty--;
- break;
- }
- }
- }
- }
- }
- printf("%d",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment