# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
647829 | ymm | Garage (IOI09_garage) | C++17 | 2 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |