답안 #956417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956417 2024-04-01T19:09:42 Z emad234 Garage (IOI09_garage) C++17
100 / 100
2 ms 2648 KB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e5 + 5;
using namespace std;
ll val[mxN];
ll w[mxN];
ll pk[mxN];
int main(){
    int n,m;
    cin >>n>>m;
    priority_queue<int,vector<int>,greater<int>>q;
    for(int i = 1;i <= n;i++){
        cin >>val[i];
        q.push(i);
    }
    queue<int>car;
    ll ans = 0;
    for(int i = 1;i <= m;i++) cin >>w[i];
    for(int i = 0;i < m * 2;i++){
        int x;
        cin >>x;
        if(x > 0){
            if(q.size()){
                ans += val[q.top()] * w[x];
                pk[x] = q.top();
                q.pop();
            }else{
                car.push(x);
            }
        }else{
            x *= -1;
            if(car.size()){
                ans += w[car.front()] * val[pk[x]];
                pk[car.front()] = pk[x];
                car.pop();
            }else{
                q.push(pk[x]);
            }
        }
    }
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 1 ms 2404 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2392 KB Output is correct