Submission #879615

# Submission time Handle Problem Language Result Execution time Memory
879615 2023-11-27T18:11:48 Z amin_2008 Garage (IOI09_garage) C++17
100 / 100
1 ms 604 KB
/*    author: amin     */

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)
#define vi vector<int>v
#define vs vector<string>v
#define vc vector<char>v
#define ll long long
#define vl vector<ll>v
#define pb push_back
#define ins insert
#define ts to_string
#define st stoi
#define ull unsigned long long
#define endl '\n'

using namespace std;

int p[101], w[2001];
set<int> s;
map<int,int> mp;
deque<int> d;

const int MOD = 1e9 + 7;

void solve()
{
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        s.ins(i);
    for(int i = 1; i <= n; i++)
        cin >> p[i];
    for(int i = 1; i <= m; i++)
        cin >> w[i];
    int res = 0;
    for(int i = 1; i <= 2 * m; i++) {
        int car;
        cin >> car;
        if (car > 0) {
            if (!s.empty()) {
                int pp = *s.begin();
                res += w[car] * p[pp];
                s.erase(s.begin());
                mp[car] = pp;
            }
            else {
                d.push_back(car);
            }
        }
        else {
            int pp = mp[-car];
            if (!d.empty()) {
                int pc = d[0];
                res += w[pc] * p[pp];
                mp[pc] = pp;
                d.pop_front();
            }
            else {
                s.ins(pp);
            }
        }
    }
    cout << res << endl;
}


int main ()
{
    ios;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 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 344 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 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