# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
522411 | 2022-02-04T22:55:48 Z | nurlitadf | Garage (IOI09_garage) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; ll modexp(ll b, ll e, ll m){ ll r = 1; while(e > 0){ if((e & 1) == 1){ r = (r * b) % m; } e >>= 1; b = (b * b) % m; } return r; } bool isvowel(char ch) { return (ch == 'a') || (ch == 'e') ||(ch == 'i') ||(ch == 'o') ||(ch == 'u') ||(ch == 'y'); } int main() { int n, m; cin >> n >> m; vector<int> rates; for(int i = 0; i < n; i++) { int v; cin >> v; rates.push_back(v); } vector<int> cars; for(int i = 0; i < m; i++) { int v; cin >> v; cars.push_back(v); } vector<int> space(n, -1); vector<int> car_to_space(n, -1); ll ans = 0; queue<int> q; for(int i = 0; i < m * 2; i++) { int v; cin >> v; if(v > 0) { v--; bool found = false; for(int j = 0; j < n; j++) { if(space[j] == -1) { space[j] = v; car_to_space[v] = j; ans += rates[j] * cars[v]; found = true; // cout << "~~~ " << v << " " << j << endl; break; } } if(!found) q.push(v); } else { v = abs(v) - 1; int s = car_to_space[v]; space[s] = -1; if(!q.empty()) { int c = q.front() q.pop(); space[s] = c; car_to_space[c] = s; ans += rates[s] * cars[c]; } car_to_space[v] = -1; } } cout << ans << endl; return 0; }