Submission #739218

# Submission time Handle Problem Language Result Execution time Memory
739218 2023-05-10T08:18:18 Z Unforgettablepl Garage (IOI09_garage) C++17
100 / 100
1 ms 340 KB
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
//#define f first
//#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("measurement.in","r",stdin);
//    freopen("measurement.out","w",stdout);
    int n,m;
    cin >> n >> m;
    vector<ll> spaces(n);
    vector<ll> weights(m);
    vector<ll> events(2*m);
    set<ll> free_spaces;
    vector<ll> taken(m,-1);
    queue<ll> line;
    for(ll&i:spaces)cin>>i;
    for(ll&i:weights)cin>>i;
    for(ll&i:events)cin>>i;
    for (int i = 0; i < n; i++) {
        free_spaces.emplace(i);
    }
    ll ans = 0;
    for(ll&i:events){
        if(i>0){
            // Car cum
            if(!free_spaces.empty()){
                taken[i-1]=*free_spaces.begin();
                ans+=spaces[*free_spaces.begin()]*weights[i-1];
                free_spaces.erase(free_spaces.begin());
            } else {
                line.emplace(i-1);
            }
        } else {
            // Car go
            i = -i; // Convert to gud
            free_spaces.emplace(taken[i-1]); // Return
            // process queue
            if(!line.empty()){
                taken[line.front()]=*free_spaces.begin();
                ans+=spaces[*free_spaces.begin()]*weights[line.front()];
                free_spaces.erase(free_spaces.begin());
                line.pop();
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct