# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697666 | europium | Garage (IOI09_garage) | C++17 | 2 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// - 11/2/23
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iterator>
#include <set>
#include <map>
#include <math.h>
#include <iomanip>
#include <unordered_set>
#include <queue>
#include <climits>
using namespace std;
// clang++ -std=c++17 IOI09_Garage.cpp && ./a.out
using ll = long long;
void solve(){
int n, m;
cin >> n >> m;
vector<int> r(n), w(m), p(n);
for (int& e : r) cin >> e;
for (int& e : w) cin >> e;
int ans = 0, free = n;
queue<int> q;
for (int t = 0; t < 2 * m; t++){
int e;
cin >> e;
if (e > 0){
if (free == 0){
q.push(e);
}
else{
free--;
for (int i = 0; i < n; i++){
if (p[i] == 0){
p[i] = e;
ans += r[i] * w[e - 1];
break;
}
}
}
}
else{
for (int i = 0; i < n; i++){
if (p[i] == abs(e)){
if (q.empty()){
free++;
p[i] = 0;
}
else{
int e = q.front();
p[i] = e;
ans += r[i] * w[e - 1];
q.pop();
}
}
}
}
}
cout << ans;
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("input.txt", "r", stdin);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |