제출 #289693

#제출 시각아이디문제언어결과실행 시간메모리
289693b00n0rpGarage (IOI09_garage)C++17
100 / 100
1 ms512 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define pb push_back
#define INF 100000000
#define mp make_pair

ll n,m,ans = 0,x;
ll r[101];
ll w[2001];
ll pos[2001];
ll status[101];

int main() {
	
	ios::sync_with_stdio(false);
	cin >> n >> m;
	fill(pos,pos+m+1,0);
	fill(status,status+n+1,0);
	for (int i = 1; i <= n; i++) cin >> r[i];
	for (int i = 1; i <= m; i++) cin >> w[i];
	queue<int> q;
	for (int lol = 0; lol < 2*m; lol++){
	    cin >> x;
	    if (x > 0){
	        if (!q.empty()) q.push(x);
	        else{
	            bool f = true;
	            for (int i = 1; i <= n; i++){
	                if (!status[i]){
	                    f = false;
	                    status[i] = x;
	                    pos[x] = i;
	                    ans += w[x]*r[i];
	                    break;
	                }
	            }
	            if (f) q.push(x);
	        } 
	    }
	    else{
	        x = -x;
	        status[pos[x]] = 0;
	        if (!q.empty()){
	            int next = q.front();
	            q.pop();
	            status[pos[x]] = next;
	            pos[next] = pos[x];
	            ans += w[next]*r[pos[next]];
	        }
	        pos[x] = 0;
	    }
	}
	cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...