Submission #1119749

# Submission time Handle Problem Language Result Execution time Memory
1119749 2024-11-27T11:40:40 Z kasdo Garage (IOI09_garage) C++14
100 / 100
3 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n, m;
    cin>>n>>m;
    int a[n + 5], b[m + 5];
    
    priority_queue<int> q;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        q.push(-i);
    }
    for(int i=1; i<=m; i++) cin>>b[i];
    
    int park[m + 5];
    vector<int> proc;
    int ans = 0;
    for(int i=1; i<=2*m; i++)
    {
        int x;
        cin>>x;
        
        if (x > 0) // join
        {
            if (q.size() > 0) // there is a parking
            {
                int cur = q.top();
                cur *= -1;
                
                park[x] = cur;
                ans += a[cur] * b[x];
                q.pop();
            }
            else // there is no parking
            {
                proc.push_back(x);
            }
        }
        else
        {
            q.push(-park[-x]);
            
            bool f = 0;
            if (q.size() > 0 && proc.size() > 0)
            {
                f = 1;
                reverse(proc.begin(), proc.end());
            }
            while(q.size() > 0 && proc.size() > 0)
            {
                int cur = q.top();
                cur *= -1;
                
                int idx = proc.back();
                
                park[idx] = cur;
                ans += a[cur] * b[idx];
                q.pop();
                proc.pop_back();
            }
            if (f && proc.size() > 0) reverse(proc.begin(), proc.end());
        }
    }
    cout<<ans<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 3 ms 340 KB Output is correct