# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
262218 | BlancaHM | Garage (IOI09_garage) | C++14 | 1 ms | 416 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.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N, M, q, prof;
cin >> N >> M;
int R[N], W[M], occ[N], pos[M];
for (int i = 0; i < N; i++) {
cin >> R[i];
occ[i] = 0;
}
for (int i = 0; i < M; i++) cin >> W[i];
prof = 0;
bool space;
queue<int> Q;
for (int i = 0; i < 2*M; i++) {
cin >> q;
if (q < 0) {
q = abs(q);
if (!Q.empty()) {
occ[pos[q-1]] = Q.front();
pos[Q.front()-1] = pos[q-1];
prof += W[Q.front()-1]*R[pos[Q.front()-1]];
Q.pop();
} else {
occ[pos[q-1]] = 0;
}
} else {
space = false;
for (int j = 0; j < N; j++) {
if (occ[j] == 0) {
space = true;
pos[q-1] = j;
occ[j] = q;
prof += W[q-1]*R[j];
break;
}
}
if (!space) Q.push(q);
}
}
cout << prof << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |