Submission #871936

# Submission time Handle Problem Language Result Execution time Memory
871936 2023-11-12T00:21:06 Z _uros9 Garage (IOI09_garage) C++17
100 / 100
1 ms 600 KB
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;




signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int n,m;
    cin >> n >> m;
    vector<int> mnozi(n);
    for(auto&x:mnozi)
        cin >> x;
    vector<int> tezine(m);
    for(auto&x:tezine)
        cin >> x;
    int rez=0;
    vector<int> parking(n,-1);
    queue<int> red;
    m*=2;
    while(m--){
        int radnja;
        cin >> radnja;
        int br=abs(radnja);
        br--;
        if(radnja<0){
            int index_u_parkingu=find(parking.begin(),parking.end(),br)-parking.begin();
            parking[index_u_parkingu]=-1;
            if(red.empty()) continue;
            int drugi=red.front();
            red.pop();
            int ubacuj_na=find(parking.begin(),parking.end(),-1)-parking.begin();
            parking[ubacuj_na]=drugi;
            rez+=tezine[drugi]*mnozi[ubacuj_na];
            continue;
        }
        if(count(parking.begin(),parking.end(),-1)==0){
            red.push(br);
            continue;
        }
        int ubacuj_na=find(parking.begin(),parking.end(),-1)-parking.begin();
        parking[ubacuj_na]=br;
        rez+=tezine[br]*mnozi[ubacuj_na];
    }
    cout << rez;


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 456 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct