# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
963072 | coolboy19521 | Garage (IOI09_garage) | C++17 | 2 ms | 2652 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
namespace ddr {
# define bpc(bt) __builtin_popcountll(bt)
# define bcl(bt) __builtin_clz(bt)
# define alr(v) rbegin(v), end(v)
# define all(v) begin(v), end(v)
# define si(v) ((ll)v.size())
# define mp make_pair
# define pb push_back
# define ins insert
# define se second
# define fi first
template <class T, class U> using pi = std::pair <T, U>;
template <class T> using pq = std::priority_queue <T>;
template <class T> using mt = std::multiset <T>;
template <class T> using ve = std::vector <T>;
template <class T> using qu = std::queue <T>;
typedef std::string str;
typedef long long ll;
typedef bool bo;
typedef char ch;
using namespace std;
const ll inf = 1e18 + 18;
}
using namespace ddr;
const ll sz = 3e5 + 15;
ll n, m, c, i, j;
ll r[sz], w[sz];
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n >> m;
for (i = 1; i <= n; i ++) {
cin >> r[i];
}
for (i = 1; i <= m; i ++) {
cin >> w[i];
}
map <ll, ll> t;
pq <ll> p;
qu <ll> q;
for (i = 1; i <= n; i ++) {
p.push(-i);
}
c = 0;
for (i = 0; i < 2 * m; i ++) {
ll a;
cin >> a;
if (a > 0) {
if (!p.empty()) {
t[a] = p.top();
p.pop();
c += w[a] * r[-t[a]];
} else {
q.push(a);
}
} else {
p.push(t[-a]);
if (!q.empty()) {
ll a = q.front();
q.pop();
t[a] = p.top();
p.pop();
c += w[a] * r[-t[a]];
}
}
}
cout << c;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |