제출 #999288

#제출 시각아이디문제언어결과실행 시간메모리
999288SonicMLGarage (IOI09_garage)C++14
100 / 100
1 ms436 KiB
#include <iostream> #include <queue> using namespace std; int n, m; int const NMAX = 100; int arr[1 + NMAX]; int taken[1 + NMAX]; int const MMAX = 2000; int weight[1 + MMAX]; int pos[1 + MMAX]; queue <int> q; int main() { cin >> n >> m; for(int i = 1;i <= n;i++) { cin >> arr[i]; } for(int i = 1;i <= m;i++) { cin >> weight[i]; } int canPark = n, ans = 0; for(int t = 1;t <= 2 * m;t++) { int c; cin >> c; if(c > 0) { if(canPark == 0) { q.push(c); }else { bool foundSpot = false; for(int i = 1;i <= n && !foundSpot;i++) { if(taken[i] == false) { ans += arr[i] * weight[c]; taken[i] = true; foundSpot = true; canPark--; pos[c] = i; } } } } else { c = -c; if(canPark == 0) { if(!q.empty()) { ans += arr[pos[c]] * weight[q.front()]; pos[q.front()] = pos[c]; q.pop(); }else{ taken[pos[c]] = false; canPark++; } } else { taken[pos[c]] = false; canPark++; } } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...