Submission #1324320

#TimeUsernameProblemLanguageResultExecution timeMemory
1324320hyyhGarage (IOI09_garage)C++20
100 / 100
2 ms332 KiB
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <iomanip>
#include <set>
#include <bitset>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using piii = tuple<int,int,int>;
#define endl '\n'
#define f first
#define s second


int main(){
    int n,m;cin >> n >> m;
    vector<int> park(n);
    for(auto &i:park) cin >> i;
    vector<int> weight(m);
    for(auto &i:weight) cin >> i;
    queue<int> q;
    vector<int> full(n,0);
    int sum = 0;
    for(int i{};i < m*2;i++){
        int g;cin >> g;
        if(g > 0){
            q.push(g);
        }
        else{
            for(int i = 0;i < n;i++){
                if(full[i] == -g){
                    full[i] = 0;
                }
            }
        }
        for(int i = 0;i < n;i++){
            if(q.empty()) break;
            if(full[i] == 0){
                sum += park[i]*weight[q.front()-1];
                full[i] = q.front();q.pop();
                
            }
        }
    }
    cout << sum;
}
#Verdict Execution timeMemoryGrader output
Fetching results...