2018年5月23日 星期三

(IOI) 2009 Day 2 p1 Garage

https://contest.yandex.com/ioi/contest/1363/problems/E/

implementation task (?

#include <bits/stdc++.h>
using namespace std;

const int N = 5006;

int r[N];
int w[N];

int hhave[N];

int main ()
{
    int n,m;
    scanf("%d %d",&n,&m);
    //n --> parking space
    //m --> cars
    for (int i=1;n>=i;i++)
    {
        scanf("%d",&r[i]);
    }
    for (int i=1;m>=i;i++)
    {
        scanf("%d",&w[i]);
    }
    int ans=0;
    deque<int> wait;
    for (int i=1;2*m>=i;i++)
    {
        int x;
        scanf("%d",&x);
        if (x>0)
        {
            bool found = false;
            for (int j=1;n>=j;j++)
            {
                if (hhave[j] == 0)
                {
                    ans += r[j] * w[x];
                    hhave[j] = x;
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                wait.push_back(x);
            }
        }
        else if (x < 0)
        {
            x = -x;
            for (int i=1;n>=i;i++)
            {
                if (hhave[i] == x)
                {
                    hhave[i] = 0;
                    if (!wait.empty())
                    {
                        hhave[i] = wait[0];
                        ans += w[ wait[0] ] * r[i];
                        wait.pop_front();
                    }
                }
            }
        }
    }
    printf("%d\n",ans);
}

沒有留言:

張貼留言