# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647829 | ymm | 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.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 2010;
int occupied_by[N];
int rate[N];
int weight[N];
queue<int> que;
pii events[2*N];
int n, m;
int first_free()
{
Loop (i,0,n)
if (occupied_by[i] == -1)
return i;
return -1;
}
void leave(int x)
{
Loop (i,0,n)
if (occupied_by[i] == x)
occupied_by[i] = -1;
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n >> m;
Loop (i,0,n)
cin >> rate[i];
Loop (i,0,m)
cin >> weight[i];
Loop (i,0,2*m) {
int x;
cin >> x;
if (x>0)
--x;
events[i] = {i, x};
}
sort(events, events+2*m);
memset(occupied_by, -1, sizeof(occupied_by));
int ans = 0;
Loop (i,0,2*m) {
int x = events[i].second;
if (x >= 0)
que.push(x);
else
leave(~x);
while (que.size() && first_free() != -1) {
int p = first_free();
int c = que.front();
que.pop();
occupied_by[p] = c;
ans += rate[p] * weight[c];
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |