SuitNdtie

GARAGE PROG 2035

Mar 9th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<queue>
  3. using namespace std;
  4.  
  5. typedef struct{
  6.     int cost;
  7.     int car;
  8. }garage;
  9.  
  10. int main()
  11. {
  12.     int n,m;
  13.     scanf("%d %d",&n,&m);
  14.     garage gar[n];
  15.     int coempty = n;
  16.     for(int i=0;i<n;i++){
  17.         scanf("%d",&gar[i].cost);
  18.         gar[i].car = 0;
  19.     }
  20.     int weight[m];for(int i=0;i<m;i++)scanf("%d",&weight[i]);
  21.    
  22.     int table[2*m];
  23.     int ans = 0;
  24.     queue<int> queue;
  25.     for(int i=0;i<2*m;i++){
  26.         scanf("%d",&table[i]);
  27.         if(table[i] > 0){ // car in
  28.             if(coempty > 0){// empty
  29.                 for(int j=0;j<n;j++){
  30.                     if(gar[j].car == 0){
  31.                         gar[j].car = table[i];
  32.                         ans += gar[j].cost * weight[gar[j].car-1];
  33.                         coempty--;
  34.                         break;
  35.                     }
  36.                 }
  37.             }else{ // not empty
  38.                 queue.push(table[i]);
  39.             }
  40.         }
  41.         else if(table[i] < 0){ // car out
  42.             for(int j=0;j<n;j++){
  43.                 if(gar[j].car == -1*table[i]){
  44.                     gar[j].car = 0;
  45.                     coempty++;
  46.                     break;
  47.                 }
  48.             }
  49.             if(!queue.empty()){ //cars are queued
  50.                 for(int j=0;j<n;j++){
  51.                     if(gar[j].car == 0){
  52.                         gar[j].car = queue.front();
  53.                         ans += gar[j].cost * weight[gar[j].car-1];
  54.                         queue.pop();
  55.                         coempty--;
  56.                         break;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.     }
  62.     printf("%d",ans);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment